@php use App\Filament\Pages\ChooseTenant; use App\Filament\Pages\ChooseWorkspace; use App\Models\Tenant; use App\Models\User; use App\Support\OperateHub\OperateHubShell; use App\Support\Workspaces\WorkspaceContext; use Filament\Facades\Filament; /** @var WorkspaceContext $workspaceContext */ $workspaceContext = app(WorkspaceContext::class); $resolvedContext = app(OperateHubShell::class)->resolvedContext(request()); $workspace = $resolvedContext->workspace; $user = auth()->user(); $tenants = collect(); if ($user instanceof User && $workspace) { $tenants = collect($user->getTenants(Filament::getCurrentOrDefaultPanel())) ->filter(fn ($tenant): bool => $tenant instanceof Tenant && (int) $tenant->workspace_id === (int) $workspace->getKey()) ->values(); } $currentTenant = $resolvedContext->tenant; $currentTenantId = $currentTenant instanceof Tenant ? (int) $currentTenant->getKey() : null; $currentTenantName = $currentTenant instanceof Tenant ? $currentTenant->getFilamentName() : null; $lastTenantId = $workspaceContext->lastTenantId(request()); $canClearTenantContext = $currentTenant instanceof Tenant || $lastTenantId !== null; @endphp @php $tenantLabel = $currentTenantName ?? 'No tenant selected'; $workspaceLabel = $workspace?->name ?? 'Choose workspace'; $hasActiveTenant = $currentTenantName !== null; $managedTenantsUrl = $workspace ? route('admin.workspace.managed-tenants.index', ['workspace' => $workspace]) : route('admin.onboarding'); $workspaceUrl = $workspace ? route('admin.home') : ChooseWorkspace::getUrl(panel: 'admin'); $tenantTriggerLabel = $workspace ? $tenantLabel : 'Choose workspace'; @endphp
{{-- Workspace label: standalone link --}} {{ $workspaceLabel }} @if ($workspace) @endif {{-- Dropdown trigger: tenant label + chevron --}}
@if ($resolvedContext->showsRecoveryNotice())
Context unavailable
@if ($workspace)
The requested scope could not be restored. The shell is showing a valid workspace state instead.
@else
Choose a workspace to continue with a valid admin context.
@endif
@endif {{-- Workspace section --}}
Workspace
{{ $workspaceLabel }}
Switch workspace
Workspace Home
@if ($workspace)
{{-- Tenant section --}}
Selected tenant
@if ($resolvedContext->pageCategory->requiresExplicitTenant() && $hasActiveTenant)
{{ $currentTenantName }} Switch tenant
@if ($canClearTenantContext)
@csrf
@endif
@else @if ($tenants->isEmpty())
No active tenants are available for the standard operating context in this workspace.
View managed tenants
@else @if (! $hasActiveTenant)
No tenant selected. Workspace-wide pages remain available, and choosing a tenant only sets the normal active operating context.
@endif
@foreach ($tenants as $tenant) @php $isActive = $currentTenantId !== null && (int) $tenant->getKey() === $currentTenantId; @endphp
@csrf
@endforeach
@if ($canClearTenantContext)
@csrf
@endif @endif @endif
@else
Choose a workspace first.
@endif