@php use Nwidart\Modules\Facades\Module; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; use App\Models\ModulePermission; use Illuminate\Support\Str; $currentUser = Auth::user(); $paymentGatewaySidebarModules = []; $otherSidebarModules = []; $installedPaymentGatewaysExist = false; // For the "Payment Gateways Dashboard" link if ($currentUser && class_exists(Module::class)) { $allEnabledModules = Module::allEnabled(); foreach ($allEnabledModules as $module) { $adminMenuConfig = $module->get('admin_menu'); $moduleName = $module->getName(); // Canonical module name $moduleCategory = $module->get('category'); if ($adminMenuConfig && isset($adminMenuConfig['route_name']) && Route::has($adminMenuConfig['route_name'])) { if ($moduleCategory === 'payment_gateway') { $installedPaymentGatewaysExist = true; // Set flag if any payment gateway is found } $canShow = false; if ($currentUser->isSuperAdmin()) { $canShow = true; } elseif ($currentUser->hasRole('admin')) { $hasModulePermission = ModulePermission::where('role_name', 'admin') ->where('module_name', $moduleName) ->exists(); $spatiePermissionRequired = $adminMenuConfig['permissions'] ?? null; $hasSpatiePermission = true; // Assume true (no specific Spatie permission needed or list is empty) // Only perform Spatie permission check if $spatiePermissionRequired is non-null AND non-empty if (!is_null($spatiePermissionRequired) && !empty($spatiePermissionRequired)) { $hasSpatiePermission = is_array($spatiePermissionRequired) ? $currentUser->hasAnyPermission($spatiePermissionRequired) // For an array of permissions : $currentUser->can($spatiePermissionRequired); // For a single permission string } $canShow = $hasModulePermission && $hasSpatiePermission; } if ($canShow) { $moduleData = [ 'title' => $adminMenuConfig['title'] ?? $module->getName(), 'route_name' => $adminMenuConfig['route_name'], 'icon_svg_path' => $adminMenuConfig['icon_svg_path'] ?? 'M8.25 6.75h7.5M8.25 12h7.5m-7.5 5.25h7.5M3.75 6.75h.007v.008H3.75V6.75zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0zM3.75 12h.007v.008H3.75V12zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0zm-.375 5.25h.007v.008H3.75v-.008zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z', // Default icon 'order' => $adminMenuConfig['order'] ?? 999, 'name' => $module->getName(), // For active route checking ]; if ($moduleCategory === 'payment_gateway') { $paymentGatewaySidebarModules[] = $moduleData; } else { $otherSidebarModules[] = $moduleData; } } } } // Sort modules by order, then by title $sortModules = function ($a, $b) { if ($a['order'] == $b['order']) { return strcmp($a['title'], $b['title']); } return $a['order'] < $b['order'] ? -1 : 1; }; usort($paymentGatewaySidebarModules, $sortModules); usort($otherSidebarModules, $sortModules); } // Determine SAAS dropdown visibility and active state $showSaasDropdown = false; $isSaasRouteActive = false; $subscriptionsEnabled = function_exists('setting') && setting('subscriptions_enabled', '0') == '1'; $creditsSystemEnabled = function_exists('setting') && setting('credits_system_enabled', '0') == '1'; $walletSystemEnabled = function_exists('setting') && setting('wallet_system_enabled', '0') == '1'; if ($subscriptionsEnabled) { $showSaasDropdown = true; if (request()->routeIs('admin.subscription-plans.*')) $isSaasRouteActive = true; } if ($currentUser->isSuperAdmin()) { if ($creditsSystemEnabled) { $showSaasDropdown = true; if (request()->routeIs('admin.feature-credit-costs.*') || request()->routeIs('admin.credit-transactions.*')) $isSaasRouteActive = true; } if ($walletSystemEnabled) { $showSaasDropdown = true; if (request()->routeIs('admin.wallet-transactions.*')) $isSaasRouteActive = true; } } // Determine if the payment gateway dropdown should be open $isPaymentGatewayRouteActive = false; foreach ($paymentGatewaySidebarModules as $pgModule) { if (request()->routeIs('admin.' . Str::kebab($pgModule['name']) . '.*') || request()->routeIs($pgModule['route_name'].'*')) { $isPaymentGatewayRouteActive = true; break; } } @endphp