@php $type = $type ?? null; $currentSlug = isset($content) ? ($content->slug ?? null) : null; // set on CMS page views only /* * Sidebar = the menu section this page belongs to: all submenu items of its menu, in menu order * (group headers are skipped, their children are listed). This follows whatever is associated in * the admin (Menu / Submenu / Menu Associate Pages) and does not depend on every page sharing one type. * If the page is not in any submenu, fall back to "all pages with the same type" as before. */ $sectionItems = null; if ($currentSlug && $type && !in_array($type, ['rti', 'infrastructure'], true)) { foreach (\App\Models\Submenu::with('menu')->where('slug', $currentSlug)->get() as $hit) { if (strcasecmp((string) ($hit->route ?: optional($hit->menu)->menu_type), (string) $type) !== 0) { continue; } $sectionItems = []; $tops = \App\Models\Submenu::where('menu_id', $hit->menu_id)->whereNull('parent_id') ->orderBy('priority')->with('children')->get(); foreach ($tops as $top) { foreach ($top->children->count() ? $top->children : [$top] as $s) { switch ($s->target_type) { case 'external': $href = $s->route; break; case 'route': $href = url($s->route); break; default: $href = pagesViewUrlOrHash($s->slug, $s->route ?: optional($hit->menu)->menu_type); } $sectionItems[] = [ 'href' => $href, 'title' => $s->submenu_title, 'active' => $s->target_type === 'page' && $s->slug === $currentSlug, 'attrs' => $s->open_in_new_tab ? 'target=_blank' : '', ]; } } break; } } @endphp @if($type) @endif