Skip to content

Fix dashboard route overwritten by home redirect when using tenant slug attribute#19584

Merged
danharrin merged 2 commits intofilamentphp:4.xfrom
leek:fix/dashboard-route-tenant-slug-attribute
Mar 30, 2026
Merged

Fix dashboard route overwritten by home redirect when using tenant slug attribute#19584
danharrin merged 2 commits intofilamentphp:4.xfrom
leek:fix/dashboard-route-tenant-slug-attribute

Conversation

@leek
Copy link
Copy Markdown
Contributor

@leek leek commented Mar 29, 2026

Fixes #19582

Problem

When a panel uses ->tenant(Model::class, 'slug') with a tenant slug attribute, the Dashboard page route (filament.{panel}.pages.dashboard) is never registered. Instead, it's overwritten by the home redirect (RedirectToHomeController).

Root cause: Route::getLastGroupPrefix() returns the raw group prefix including binding syntax (admin/{tenant:slug}), but Laravel's RouteCollection indexes routes by the normalized URI without binding syntax (admin/{tenant}). The isset() check fails due to this key mismatch, so the guard thinks no root route exists and registers the home redirect — which overwrites the Dashboard.

Fix

Strip binding syntax from $rootUri before looking it up in the route collection:

// Before
$rootUri = trim(Route::getLastGroupPrefix(), '/') ?: '/';

// After
$rootUri = preg_replace('/\{(\w+):\w+\}/', '{$1}', trim(Route::getLastGroupPrefix(), '/')) ?: '/';

Tests

Added two tests that verify:

  1. The dashboard route is registered when using a tenant slug attribute
  2. The home redirect is not registered when the dashboard already occupies the root path

Both tests fail without the fix and pass with it. All existing route tests continue to pass.

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Roadmap Mar 30, 2026
@danharrin danharrin added the bug Something isn't working label Mar 30, 2026
@danharrin danharrin modified the milestones: v5, v4 Mar 30, 2026
…ug attribute

`Route::getLastGroupPrefix()` returns the raw group prefix including
binding syntax (e.g. `admin/{tenant:slug}`), but Laravel's
`RouteCollection` indexes routes by the normalized URI without binding
syntax (e.g. `admin/{tenant}`). The `isset()` check on line 182 fails
due to this key mismatch when a tenant slug attribute is configured,
causing the home redirect to be created at `/` and overwrite the
Dashboard route.

The fix strips binding syntax from the root URI before looking it up
in the route collection.

Fixes filamentphp#19582
@danharrin danharrin force-pushed the fix/dashboard-route-tenant-slug-attribute branch from 381c8a3 to 7ed97b2 Compare March 30, 2026 08:39
@danharrin danharrin changed the base branch from 5.x to 4.x March 30, 2026 08:39
@danharrin danharrin merged commit 7e4b8a5 into filamentphp:4.x Mar 30, 2026
35 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Roadmap Mar 30, 2026
@leek leek deleted the fix/dashboard-route-tenant-slug-attribute branch March 31, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Dashboard route overwritten by home redirect when using tenant slug attribute (v5.4.2 regression)

2 participants