F
Filament6mo 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
Anik5mo ago
Hello, any solution to this?
ChesterS
ChesterS5mo ago
Try this in the resource maybe?
protected static ?string $recordRouteKeyName = 'slug';
protected static ?string $recordRouteKeyName = 'slug';
but {record:slug} should have worked 🤔
Anik
Anik5mo 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
ChesterS5mo 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)