@php // Items store a plain path slug in `url` or `route` (not a registered // Laravel route name), so build hrefs the same way the rest of the site // does rather than using MenuItem::link(). $menuItemHref = function ($item) { $path = $item->url ?: $item->route; return $path ? url(rtrim($path, '/') . '/') : '#'; }; $currentUrl = url()->current(); $currentPath = trim(request()->path(), '/'); $normalizePath = function ($urlOrPath) { if (empty($urlOrPath) || $urlOrPath === '#') { return ''; } $parsed = parse_url($urlOrPath, PHP_URL_PATH); return trim($parsed ?? '', '/'); }; $isItemActive = function ($item) use ($currentUrl, $currentPath, $normalizePath, $menuItemHref) { $itemHref = $menuItemHref($item); $itemPath = $normalizePath($itemHref); // Direct match with URL or path if ($currentUrl === $itemHref || ($itemPath !== '' && $currentPath === $itemPath)) { return true; } // Subpath match (e.g. /blogs/my-post) if ($itemPath !== '' && request()->is($itemPath . '/*')) { return true; } // Check if any child item matches current page if ($item->children && $item->children->count()) { foreach ($item->children as $child) { $childHref = $menuItemHref($child); $childPath = $normalizePath($childHref); if ($currentUrl === $childHref || ($childPath !== '' && $currentPath === $childPath)) { return true; } if ($childPath !== '' && request()->is($childPath . '/*')) { return true; } } } return false; }; $hf = $headerFooter ?? collect(); $dropdownStyle = $hf->get('header_dropdown_style', 'card'); $dropdownAnim = $hf->get('header_dropdown_animation', 'slide_down'); @endphp