@php $route = request()->route(); $routeName = $route?->getName(); $routeParameters = $route?->parameters() ?? []; unset($routeParameters['tenant']); // A record identifier can point to data owned by the previous tenant. // Preserve list and standalone page routes only; record routes retain // Filament's safe dashboard destination. $canPreserveRoute = filled($routeName) && Illuminate\Support\Facades\Route::has($routeName) && ! array_key_exists('record', $routeParameters); $tenantDestinations = []; if ($canPreserveRoute && auth('admin')->check()) { foreach (filament()->getUserTenants(auth('admin')->user()) as $tenant) { try { $tenantDestinations[filament()->getUrl($tenant)] = route( $routeName, ['tenant' => $tenant, ...$routeParameters], ); } catch (\Throwable) { // Keep Filament's dashboard URL when this route cannot be // generated for another tenant. } } } @endphp @if ($tenantDestinations !== []) @endif