F
Filament12mo ago
Anish

Edit Page URL customization

I want to customize the url in the edit page of a resource to use slug in place id. I don't want to change in the model. I am using :
'edit' => Pages\EditAuthor::route('/{record:slug}/edit'),
'edit' => Pages\EditAuthor::route('/{record:slug}/edit'),
But this does not seem to work. Thanks in advance for any help.
4 Replies
Anik
Anik11mo ago
Hello, any solution to this?
ChesterS
ChesterS11mo ago
Try this in the resource maybe?
protected static ?string $recordRouteKeyName = 'slug';
protected static ?string $recordRouteKeyName = 'slug';
but {record:slug} should have worked 🤔
Anik
Anik11mo ago
also the actions need to be updated for this to work
Tables\Actions\ViewAction::make()->url(fn ($record) => BusinessBookingResource::getUrl('view', ['record' => $record->slug])),
Tables\Actions\ViewAction::make()->url(fn ($record) => BusinessBookingResource::getUrl('view', ['record' => $record->slug])),
Actually we need both to work with urls other than id
protected static ?string $recordRouteKeyName = 'url';
'view' => Pages\ViewBusiness::route('/{record:url}'),
protected static ?string $recordRouteKeyName = 'url';
'view' => Pages\ViewBusiness::route('/{record:url}'),
ChesterS
ChesterS11mo ago
The easiest way would be to change the getRouteKeyName method on the model
public function getRouteKeyName(): string
{
return 'slug';
}
public function getRouteKeyName(): string
{
return 'slug';
}
but the OP said he doesn't want to change the model (and this would change it pretty much everywhere)
Want results from more Discord servers?
Add your server