Fix dashboard route overwritten by home redirect when using tenant domain binding field (#19598)

* Fix dashboard route overwritten by home redirect when using tenant domain binding field

* Update web.php

* Update web.php

---------

Co-authored-by: Dan Harrin <git@danharrin.com>
This commit is contained in:
RenHai Wen
2026-04-02 15:13:48 +01:00
committed by GitHub
co-authored by Dan Harrin
parent b7378e7380
commit c80dbf4f98
3 changed files with 34 additions and 7 deletions
+14 -5
View File
@@ -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');
}
}
});
@@ -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 {
@@ -0,0 +1,18 @@
<?php
use Filament\Tests\Panels\Pages\TestCase;
use Illuminate\Support\Facades\Route;
uses(TestCase::class);
it('registers the dashboard route when using a tenant domain binding field', function (): void {
$route = Route::getRoutes()->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();
});