@props([ /** shared_sections.name that holds this header, so the client can edit it in the panel. */ 'section' => null, /** Banner used when that row does not exist: the image the view had hardcoded. */ 'image' => null, /** Overrides the stored title. The detail views show the record's own name. */ 'title' => null, /** Heading used ONLY when nothing is stored, so the fallback is not left without one. */ 'fallbackTitle' => null, /** Fallback breadcrumb: [['label' => '…', 'url' => '/…'], …]. */ 'crumbs' => [], /** Crumbs appended AFTER the stored ones: the category of a detail view, for instance. */ 'extra' => [], /** Hidden SEO h1. Per view, and often built from the record, so it is not stored. */ 'h1' => null, ]) @php /** * Header of a view served by a CONTROLLER, not by the page builder. * * /blogs, /machinery and /used-machines-for-sale list content that is already in the database, * but their banner, breadcrumb and heading were written into the blade, so nobody could change * them without touching code. They read a `shared_sections` row instead — which is exactly what * that table is for: one piece of content, edited once in the panel, rendered wherever. * * It falls back to what the blade had: the row is NOT `is_system` (system rows cannot be edited * in the panel, which would defeat the point), so it can be renamed or deleted — and if it is, * the view keeps its banner instead of rendering a broken one. */ $type = App\Enums\PageBlockTypeEnum::PAGE_HEADER_BREADCRUMB->value; $stored = $section === null ? null : App\Models\SharedSection::query() ->where('name', $section) ->where('type', $type) ->where('is_active', true) ->first(); $data = $stored === null ? null : ($stored->content[$type] ?? null); if (empty($data['background_image']) || empty($data['breadcrumbs'])) { // Nothing usable stored: rebuild what the blade used to print. $data = [ 'background_image_url' => $image === null ? null : asset($image), 'main_title' => $fallbackTitle, 'breadcrumbs' => collect($crumbs)->map(fn (array $crumb): array => [ 'redirect' => [ 'redirect' => ['type' => 'internal', 'value' => ltrim((string) ($crumb['url'] ?? '/'), '/')], 'button_text' => $crumb['label'] ?? '', ], ])->all(), ]; } // The detail views know their own title; the listings use the stored one. if ($title !== null) { $data['main_title'] = $title; } if ($h1 !== null) { $data['hidden_h1'] = $h1; } foreach ($extra as $crumb) { $data['breadcrumbs'][] = [ 'redirect' => [ 'redirect' => ['type' => 'internal', 'value' => ltrim((string) ($crumb['url'] ?? '/'), '/')], 'button_text' => $crumb['label'] ?? '', ], ]; } @endphp @if (!empty($data['background_image']) || !empty($data['background_image_url'])) @include('frontend.content-section.page-header-breadcrumb', ['data' => $data]) @endif