F
Filament7mo ago
gremki

Extra route parameter for a resource

Hello! I have a resource that needs an extra parameter so I've added it to pages definition:
public static function getPages(): array
{
return [
'index' => Pages\ListSubDestinations::route('{parent}/'),
'create' => Pages\CreateSubDestination::route('{parent}/create'),
'edit' => Pages\EditSubDestination::route('{parent}/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListSubDestinations::route('{parent}/'),
'create' => Pages\CreateSubDestination::route('{parent}/create'),
'edit' => Pages\EditSubDestination::route('{parent}/{record}/edit'),
];
}
But, when I access the page (...geography/sub-destinations/1), I get a "Missing required parameter" error. What am I missing here?
No description
6 Replies
gremki
gremkiOP7mo ago
I tried to get the parameter from route but, in getPages() method, request()->route() is null. Nobody has any idea?
Tetracyclic
Tetracyclic7mo ago
What do you see if you run php artisan route:list --name=filament.adminhub.geography.sub-destinations
gremki
gremkiOP7mo ago
it's filament.adminhub.resources.geography.sub-destinations.index and the result is: GET|HEAD adminhub/geography/sub-destinations/{parent} ...................... filament.adminhub.resources.geography.sub-destinations.index › App\Filament\Admin\Resources\Geography\SubDestinationResource\Pages\ListSubDestinations probably something related to lifecycle, if I make the parameter optional it works, but it's a required one...
Tetracyclic
Tetracyclic7mo ago
Ah, you may need set the following on the ListSubdestinations page: protected static bool $shouldRegisterNavigation = false; It's probably trying to register it as a navigation item by default, and it will be passing null to the route generator. That would explain why it's a UrlGenerationException
gremki
gremkiOP7mo ago
Nope, already did that...
Tetracyclic
Tetracyclic7mo ago
Can you share more detail from the error? Where's it being found in the stack trace? UrlGenerationException suggests it's trying to generate the URL somewhere and not passing it a record
Want results from more Discord servers?
Add your server