@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\Tenants\TenantPageCategory; use App\Support\Workspaces\WorkspaceContext; use Filament\Facades\Filament; /** @var WorkspaceContext $workspaceContext */ $workspaceContext = app(WorkspaceContext::class); $workspace = $workspaceContext->currentWorkspace(request()); $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(); } $operateHubShell = app(OperateHubShell::class); $currentTenant = $operateHubShell->activeEntitledTenant(request()); $currentTenantId = $currentTenant instanceof Tenant ? (int) $currentTenant->getKey() : null; $currentTenantName = $currentTenant instanceof Tenant ? $currentTenant->getFilamentName() : null; $hasAnyFilamentTenantContext = Filament::getTenant() instanceof Tenant; $route = request()->route(); $routeName = (string) ($route?->getName() ?? ''); $pageCategory = TenantPageCategory::fromRequest(request()); $tenantQuery = request()->query('tenant'); $hasTenantQuery = is_string($tenantQuery) && trim($tenantQuery) !== ''; $isTenantScopedRoute = $pageCategory === TenantPageCategory::TenantBound || ($hasTenantQuery && str_starts_with($routeName, 'filament.admin.')); $lastTenantId = $workspaceContext->lastTenantId(request()); $canClearTenantContext = $hasAnyFilamentTenantContext || $lastTenantId !== null; @endphp @php $tenantLabel = $currentTenantName ?? 'All tenants'; $workspaceLabel = $workspace?->name ?? 'Select 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 ? ($hasActiveTenant ? $tenantLabel : 'No tenant selected') : 'Select tenant'; @endphp