Route not found for Filament Resource Page

I'm an experienced PHP/Symfony developer, my experience with Laravel and Filament is very limited. I apologise in advance for a trivial question. I created a new Resource, with two pages: index, and issue. Autodiscovery seems to work fine, when I run the route:list command from the command line, I see the routes:
$ php artisan route:list | grep premiums
GET|HEAD admin/premiums ................................ filament.app.resources.premiums.index › App\Filament\Resources\PremiumResource\Pages\ListPremiums
GET|HEAD admin/premiums/{record}/issue ................. filament.app.resources.premiums.issue › App\Filament\Resources\PremiumResource\Pages\IssuePremium
$ php artisan route:list | grep premiums
GET|HEAD admin/premiums ................................ filament.app.resources.premiums.index › App\Filament\Resources\PremiumResource\Pages\ListPremiums
GET|HEAD admin/premiums/{record}/issue ................. filament.app.resources.premiums.issue › App\Filament\Resources\PremiumResource\Pages\IssuePremium
When I try to use the route in Filament's Action, I get the following error:
Internal Server Error

Symfony\Component\Routing\Exception\RouteNotFoundException
Route [filament.app.resources.premiums.issue] not defined.
Internal Server Error

Symfony\Component\Routing\Exception\RouteNotFoundException
Route [filament.app.resources.premiums.issue] not defined.
Well, clearly it's defined, as route:list lists that route... so not sure what is going on here. I have tried clearing cache, restarting the app, even restarted my PC. The relevant PHP code that tries to use the route is:
->actions([
Action::make('premiums.issue')
->label('Issue')
->url(fn (Premium $p) => route('filament.app.resources.premiums.issue', ['record' => $p->id]))
,
])
->actions([
Action::make('premiums.issue')
->label('Issue')
->url(fn (Premium $p) => route('filament.app.resources.premiums.issue', ['record' => $p->id]))
,
])
PremiumResource class:
final class PremiumResource extends Resource
{
protected static ?string $model = Premium::class;

protected static ?string $navigationGroup = null;
protected static ?int $navigationSort = null;

public static function getPages(): array
{
return [
'index' => Pages\ListPremiums::route('/'),
'issue' => Pages\IssuePremium::route('/{record}/issue'),
];
}
}
final class PremiumResource extends Resource
{
protected static ?string $model = Premium::class;

protected static ?string $navigationGroup = null;
protected static ?int $navigationSort = null;

public static function getPages(): array
{
return [
'index' => Pages\ListPremiums::route('/'),
'issue' => Pages\IssuePremium::route('/{record}/issue'),
];
}
}
ListPremiums extends ListRecords, while IssuePremium extends EditRecord. Thank you.
Solution:
I deleted bootstrap/cache/filament folder and now it automagically works...
Jump to solution
19 Replies
Dennis Koch
Dennis Koch2d ago
The relevant PHP code that tries to use the route is:
Where do you use that code? In a ServiceProvider? It might run before routes are registered.
Marek
MarekOP2d ago
in the RelationManager on listed records. I have identical set up to list customers and it works fine...
final class PremiumsRelationManager extends RelationManager
{
protected static string $relationship = 'premiums';

public function table(Table $table): Table
{
return $table
->paginated(false)
->columns([
// ...
])
->actions([
Action::make('premiums.issue')
->label('Issue')
->url(fn (Premium $p) => route('filament.app.resources.premiums.issue', ['record' => $p->id]))
,
])
;
}
}
final class PremiumsRelationManager extends RelationManager
{
protected static string $relationship = 'premiums';

public function table(Table $table): Table
{
return $table
->paginated(false)
->columns([
// ...
])
->actions([
Action::make('premiums.issue')
->label('Issue')
->url(fn (Premium $p) => route('filament.app.resources.premiums.issue', ['record' => $p->id]))
,
])
;
}
}
the working RelationManager looks like this:
final class CustomerRelationManager extends RelationManager
{
protected static string $relationship = 'customer';

public function table(Table $table): Table
{
return $table
->paginated(false)
->columns([
// ...
])
->actions([
Action::make('customer.view')
->label('View')
->url(fn (Customer $c) => route('filament.app.resources.customers.view', ['record' => $c->id])),
])
;
}
}
final class CustomerRelationManager extends RelationManager
{
protected static string $relationship = 'customer';

public function table(Table $table): Table
{
return $table
->paginated(false)
->columns([
// ...
])
->actions([
Action::make('customer.view')
->label('View')
->url(fn (Customer $c) => route('filament.app.resources.customers.view', ['record' => $c->id])),
])
;
}
}
Dennis Koch
Dennis Koch2d ago
Should be okay. I wouldn't use the route() method directly though. You can use PremiumsResource::getUrl('issue', ['record' => $p->id]) instead which should be more reliable. Does this maybe solve the error?
Marek
MarekOP2d ago
it did not, it's really a wrapper on route() method, throws the same error.
Internal Server Error

Symfony\Component\Routing\Exception\RouteNotFoundException
Route [filament.app.resources.premiums.issue] not defined.
Internal Server Error

Symfony\Component\Routing\Exception\RouteNotFoundException
Route [filament.app.resources.premiums.issue] not defined.
$ php artisan route:list | grep filament.app.resources.premiums.issue
GET|HEAD admin/premiums/{record}/issue ................. filament.app.resources.premiums.issue › App\Filament\Resources\PremiumResource\Pages\IssuePremium
$ php artisan route:list | grep filament.app.resources.premiums.issue
GET|HEAD admin/premiums/{record}/issue ................. filament.app.resources.premiums.issue › App\Filament\Resources\PremiumResource\Pages\IssuePremium
Dennis Koch
Dennis Koch2d ago
it's really a wrapper on route() method
Yeah, makes sense 🙈 Hm, it's weird. I think I have seen the issue from times to times but it always "magically appears and disappears" again. Can it be some OpCaching? As it works on the CLI but not the browser? Can you try dumping Route::getRoutes() on any route?
Marek
MarekOP2d ago
Routes are not listed, when I dump the Route::getRoutes() output. I mean the premium related 2 routes are missing.
Dennis Koch
Dennis Koch2d ago
Sounds like OpCache to me then. What's you OS and dev environment? I guess that should be fixed by a restart though. 🤔
Solution
Marek
Marek2d ago
I deleted bootstrap/cache/filament folder and now it automagically works...
Marek
MarekOP2d ago
Sounds like OpCache to me then. What's you OS and dev environment?
Fedora Linux (latest) with PHP 8.3.20
Dennis Koch
Dennis Koch2d ago
Well, if deleting that folder helped it's probably not OpCache. Did you run artisan filament:optimize or similar at any point?
Marek
MarekOP2d ago
weird that running php artisan cache:clear didn't clear it
Did you run artisan filament:optimize or similar at any point?
No, just php artisan cache:clear 😞 but I may have run it earlier (before 3 weeks holiday I just returned from 😅 )
Dennis Koch
Dennis Koch2d ago
optimize is the reverse and I think cache:clear doesn't work for the "Filament cache". That's why I'm asking
Marek
MarekOP2d ago
I'll just make myself another make target to clear cache + optimise
Dennis Koch
Dennis Koch2d ago
There is artisan filament:optimize-clear to clear the Filament optimisations.
Marek
MarekOP2d ago
I guess I do not need them on local dev, right?
Dennis Koch
Dennis Koch2d ago
The Blade icon cache could help. See whether you notice a difference 😅
Marek
MarekOP2d ago
😅 Thank you for your help! @Dennis Koch would it make sense to hook optimize-clear when user requests cache:clear? 🤔
toeknee
toeknee2d ago
Doesn't optimize-clear run cache:clear?
Marek
MarekOP2d ago
possibly

Did you find this page helpful?