@php $team = auth()->user()?->currentTeam(); $projectUuid = request()->route('project_uuid'); $environmentUuid = request()->route('environment_uuid'); $projects = $projectUuid && $team ? $team->projects()->get() : collect(); $currentProject = $projectUuid ? $projects->firstWhere('uuid', $projectUuid) : null; $environments = $currentProject ? $currentProject->environments()->get() : collect(); $currentEnvironment = $environmentUuid ? $environments->firstWhere('uuid', $environmentUuid) : null; $projectDestinationRoute = request()->routeIs('shared-variables.project.*') ? 'shared-variables.project.show' : 'project.show'; $applicationUuid = request()->route('application_uuid'); $currentApplication = $currentEnvironment && $applicationUuid ? $currentEnvironment->applications()->where('uuid', $applicationUuid)->first() : null; $databaseUuid = request()->route('database_uuid'); $currentDatabase = $currentEnvironment && $databaseUuid ? $currentEnvironment->databases()->firstWhere('uuid', $databaseUuid) : null; $serviceUuid = request()->route('service_uuid'); $currentService = $currentEnvironment && $serviceUuid ? $currentEnvironment->services()->where('uuid', $serviceUuid)->first() : null; $currentResource = $currentApplication ?? $currentDatabase ?? $currentService; $resourceItems = $currentEnvironment ? collect() ->concat($currentEnvironment->applications->map(fn ($application) => [ 'type' => 'application', 'resource' => $application, ])) ->concat($currentEnvironment->databases()->map(fn ($database) => [ 'type' => 'database', 'resource' => $database, ])) ->concat($currentEnvironment->services->map(fn ($service) => [ 'type' => 'service', 'resource' => $service, ])) ->sortBy(fn ($item) => strtolower($item['resource']->name)) ->map(fn ($item) => [ 'label' => $item['resource']->name, 'href' => match ($item['type']) { 'application' => route('project.application.configuration', [ 'project_uuid' => $currentProject->uuid, 'environment_uuid' => $currentEnvironment->uuid, 'application_uuid' => $item['resource']->uuid, ]), 'database' => route('project.database.configuration', [ 'project_uuid' => $currentProject->uuid, 'environment_uuid' => $currentEnvironment->uuid, 'database_uuid' => $item['resource']->uuid, ]), 'service' => route('project.service.configuration', [ 'project_uuid' => $currentProject->uuid, 'environment_uuid' => $currentEnvironment->uuid, 'service_uuid' => $item['resource']->uuid, ]), }, 'active' => $item['resource']->uuid === $currentResource?->uuid, ]) ->values() : collect(); $storageUuid = request()->route('storage_uuid'); $storages = $storageUuid && $team ? \App\Models\S3Storage::ownedByCurrentTeam()->orderBy('name')->get() : collect(); $currentStorage = $storages->firstWhere('uuid', $storageUuid); $githubAppUuid = request()->route('github_app_uuid'); $gitlabAppUuid = request()->route('gitlab_app_uuid'); $sourceUuid = $githubAppUuid ?? $gitlabAppUuid; $sources = $sourceUuid && $team ? $team->sources()->sortBy('name')->values() : collect(); $currentSource = $sources->firstWhere('uuid', $sourceUuid); $destinationUuid = request()->route('destination_uuid'); $destinations = $destinationUuid && $team ? \App\Models\Server::isUsable() ->with(['standaloneDockers', 'swarmDockers']) ->get() ->flatMap(fn ($server) => $server->standaloneDockers->concat($server->swarmDockers)) ->sortBy('name') ->values() : collect(); $currentDestination = $destinations->firstWhere('uuid', $destinationUuid); $tagName = request()->route('tagName'); $tags = $tagName && $team ? \App\Models\Tag::ownedByCurrentTeam()->orderBy('name')->get()->unique('name')->values() : collect(); $currentTag = $tags->firstWhere('name', $tagName); $dashboardContext = match (true) { request()->routeIs('dashboard') => 'Dashboard', request()->routeIs('project.index') => 'Projects', request()->routeIs('terminal') => 'Terminal', request()->routeIs('server.*') => 'Servers', request()->routeIs('source.*') => 'Sources', request()->routeIs('destination.*') => 'Destinations', request()->routeIs('storage.*') => 'S3 Storage', request()->routeIs('shared-variables.*') => 'Shared Variables', request()->routeIs('team.*') => 'Team', request()->routeIs('notifications.*') => 'Notifications', request()->routeIs('security.*') => 'Keys & Tokens', request()->routeIs('tags.*') => 'Tags', request()->routeIs('settings.*') => 'Settings', request()->routeIs('profile*') => 'Profile', request()->routeIs('admin.*') => 'Admin', default => null, }; // Workspace destinations require an active plan on cloud; unsubscribed users // only keep profile/appearance and must not see this switcher. $canUseWorkspaceNav = isSubscribed() || ! isCloud(); $pageDestinations = $canUseWorkspaceNav ? collect([ ['label' => 'Dashboard', 'href' => url('/')], ['label' => 'Projects', 'href' => url('/projects')], auth()->user()?->can('canAccessTerminal') ? ['label' => 'Terminal', 'href' => route('terminal')] : null, ['label' => 'Servers', 'href' => url('/servers')], ['label' => 'Sources', 'href' => route('source.all')], ['label' => 'Destinations', 'href' => route('destination.index')], ['label' => 'S3 Storage', 'href' => route('storage.index')], ['label' => 'Shared Variables', 'href' => route('shared-variables.index')], ['label' => 'Team', 'href' => route('team.index')], ['label' => 'Notifications', 'href' => route('notifications.email')], ['label' => 'Keys & Tokens', 'href' => route('security.private-key.index')], ['label' => 'Tags', 'href' => route('tags.show')], isInstanceAdmin() ? ['label' => 'Settings', 'href' => route('settings.index')] : null, ])->filter() : collect(); @endphp