@php use App\Services\PermissionService; $role = auth()->user()->role?->slug ?? 'admin'; $user = auth()->user(); $isPlatformPanel = request()->is('admin', 'admin/*'); $isCompanyPanel = request()->is('company', 'company/*'); $isStudentPanel = request()->is('learner', 'learner/*'); $instructorMenu = [ ['label' => 'Dashboard', 'route' => 'instructor.dashboard', 'icon' => 'M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6'], ]; $learnerMenu = [ ['label' => 'Dashboard', 'route' => 'learner.dashboard', 'icon' => 'M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6'], ['label' => 'My Courses', 'route' => 'learner.courses.index', 'icon' => 'M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253'], ['label' => 'Certificates', 'route' => 'learner.certificates', 'icon' => 'M9 12l2 2 4-4M7.835 4.697a3.42 3.42 0 001.946-.806 3.42 3.42 0 014.438 0 3.42 3.42 0 001.946.806 3.42 3.42 0 013.138 3.138 3.42 3.42 0 00.806 1.946 3.42 3.42 0 010 4.438 3.42 3.42 0 00-.806 1.946 3.42 3.42 0 01-3.138 3.138 3.42 3.42 0 00-1.946.806 3.42 3.42 0 01-4.438 0 3.42 3.42 0 00-1.946-.806 3.42 3.42 0 01-3.138-3.138 3.42 3.42 0 00-.806-1.946 3.42 3.42 0 010-4.438 3.42 3.42 0 00.806-1.946 3.42 3.42 0 013.138-3.138z'], ['label' => 'Communities', 'route' => 'learner.communities.index', 'icon' => 'M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z'], ['label' => 'My Profile', 'route' => 'profile.edit', 'icon' => 'M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z'], ]; $platformSections = collect(config('platform-menu.platform', [])); $companySections = collect(config('admin-menu.admin', []))->map(function ($section) use ($user) { if (isset($section['route'])) { if (!PermissionService::canAccessRoute($user, $section['permission'] ?? null)) { return null; } return $section; } $items = collect($section['items'] ?? [])->filter(function ($item) use ($user) { if (! empty($item['hidden'])) { return false; } return PermissionService::canAccessRoute($user, $item['permission'] ?? null); })->values()->all(); if (empty($items)) { return null; } $section['items'] = $items; return $section; })->filter()->values()->all(); // Show unread institute enquiry count on Website → Enquiries. if ($isCompanyPanel && $user && method_exists($user, 'isCompanyStaff') && $user->isCompanyStaff()) { try { $enquiryCompany = \App\Services\CompanyService::resolveForUser($user); $newEnquiryCount = $enquiryCompany->enquiries()->where('status', 'new')->count(); if ($newEnquiryCount > 0) { $companySections = collect($companySections)->map(function ($section) use ($newEnquiryCount) { if (! isset($section['items'])) { return $section; } $section['items'] = collect($section['items'])->map(function ($item) use ($newEnquiryCount) { if (($item['route'] ?? null) === 'admin.company-page.enquiries') { $item['badge'] = (string) $newEnquiryCount; } return $item; })->all(); return $section; })->all(); } } catch (\Throwable $e) { // Ignore — menu should still render if company resolve fails. } } $menuSections = $isPlatformPanel ? $platformSections : $companySections; $panelTitle = $isPlatformPanel ? 'Platform Admin' : ($isStudentPanel || $role === 'learner' ? 'Student Panel' : 'Institute Panel'); $isMenuItemActive = function (array $item) use ($menuSections): bool { $route = $item['route'] ?? null; if (! $route || ! request()->routeIs($route, $route . '.*')) { return false; } $params = $item['params'] ?? []; if (! empty($params)) { foreach ($params as $key => $value) { if ((string) request($key) !== (string) $value) { return false; } } return true; } // Shared route without params: inactive when another sibling's query params match. foreach ($menuSections as $section) { $siblings = isset($section['items']) ? $section['items'] : [$section]; foreach ($siblings as $sibling) { if (($sibling['route'] ?? null) !== $route) { continue; } if (($sibling['label'] ?? null) === ($item['label'] ?? null)) { continue; } $siblingParams = $sibling['params'] ?? []; if (empty($siblingParams)) { continue; } $siblingMatches = true; foreach ($siblingParams as $key => $value) { if ((string) request($key) !== (string) $value) { $siblingMatches = false; break; } } if ($siblingMatches) { return false; } } } return true; }; $defaultOpenGroups = []; foreach ($menuSections as $section) { if (isset($section['group'])) { $defaultOpenGroups[$section['group']] = collect($section['items'])->contains( fn ($item) => $isMenuItemActive($item) ); } } @endphp