diff --git a/packages/panels/routes/web.php b/packages/panels/routes/web.php index ec385a6f2f..69f71759f3 100644 --- a/packages/panels/routes/web.php +++ b/packages/panels/routes/web.php @@ -8,6 +8,8 @@ use Filament\Facades\Filament; use Filament\Http\Controllers\RedirectToHomeController; use Filament\Http\Controllers\RedirectToTenantController; use Filament\Panel; +use Illuminate\Foundation\Application; +use Illuminate\Routing\RouteUri; use Illuminate\Support\Facades\Route; Route::name('filament.') @@ -140,6 +142,10 @@ Route::name('filament.') $routes($panel); } + if (version_compare(Application::VERSION, '13.0.0', '<')) { /** @phpstan-ignore if.alwaysFalse, if.alwaysTrue */ + Route::get('/', RedirectToHomeController::class)->name('home'); + } + Route::name('tenant.')->group(function () use ($panel): void { if ($panel->hasTenantBilling()) { Route::get($panel->getTenantBillingRouteSlug(), $panel->getTenantBillingProvider()->getRouteAction()) @@ -175,12 +181,15 @@ Route::name('filament.') Filament::setCurrentResourceConfigurationKey(null); } - $rootUri = preg_replace('/\{(\w+):\w+\}/', '{$1}', trim(Route::getLastGroupPrefix(), '/')) ?: '/'; - $groupStack = Route::getGroupStack(); - $rootKey = (end($groupStack)['domain'] ?? '') . $rootUri; + if (version_compare(Application::VERSION, '13.0.0', '>=')) { /** @phpstan-ignore if.alwaysTrue, if.alwaysFalse */ + $groupStack = Route::getGroupStack(); + $rootDomain = RouteUri::parse(end($groupStack)['domain'] ?? '')->uri; + $rootUri = RouteUri::parse(trim(Route::getLastGroupPrefix(), '/') ?: '/')->uri; + $rootKey = $rootDomain . $rootUri; - if (! isset(Route::getRoutes()->getRoutesByMethod()['GET'][$rootKey])) { - Route::get('/', RedirectToHomeController::class)->name('home'); + if (! isset(Route::getRoutes()->getRoutesByMethod()['GET'][$rootKey])) { + Route::get('/', RedirectToHomeController::class)->name('home'); + } } }); diff --git a/tests/src/Panels/Routes/SingleAndMultiDomainTest.php b/tests/src/Panels/Routes/SingleAndMultiDomainTest.php index 19132a37bc..7a9e9e39a8 100644 --- a/tests/src/Panels/Routes/SingleAndMultiDomainTest.php +++ b/tests/src/Panels/Routes/SingleAndMultiDomainTest.php @@ -36,8 +36,8 @@ it('panels with multiple domains should use the domain in names of all routes', }); it('does not register the home route when a page already owns the root path', function (): void { - expect(Route::getRoutes()->getByName('filament.single-domain.home'))->toBeNull(); - expect(Route::getRoutes()->getByName('filament.single-domain.pages.dashboard'))->not->toBeNull(); + expect(Route::getRoutes()->getByName('filament.single-domain.home'))->toBeNull() + ->and(Route::getRoutes()->getByName('filament.single-domain.pages.dashboard'))->not->toBeNull(); }); it('preserves the dashboard route when registered on a panel without a domain', function (): void { diff --git a/tests/src/Panels/Routes/TenantDomainBindingFieldTest.php b/tests/src/Panels/Routes/TenantDomainBindingFieldTest.php new file mode 100644 index 0000000000..1bc0977cbc --- /dev/null +++ b/tests/src/Panels/Routes/TenantDomainBindingFieldTest.php @@ -0,0 +1,18 @@ +getByName('filament.domain-tenancy.pages.dashboard'); + + expect($route)->not->toBeNull() + ->and($route->getDomain())->toBe('{tenant}') + ->and($route->uri())->toBe('domain-tenancy'); +}); + +it('does not register the home redirect when the dashboard occupies the root path with a tenant domain binding field', function (): void { + expect(Route::getRoutes()->getByName('filament.domain-tenancy.home'))->toBeNull(); +});