F
Filament14mo ago
Fogzy

Multiple slashes (/) in the slug lead to 404

I have an Eloquent model Category. It has a slug that has multiple slashes, like animals-pet-supplies/pet-supplies/bird-supplies/bird-cage-accessories/bird-cage-bird-baths etc. The problem is that for this route: 'edit' => Pages\EditCategory::route('/{record}/edit'), I get a 404, probably because of multiple slashes. In Laravel router, I did this ->where('category', '.*') , which helped. Is there any way to do this in Filament? It's also OK to just use the ID, not the slug, but I have no idea how to do that. I tried protected static ?string $recordRouteKeyName = 'id'; with no luck.
Solution:
```public static function getPages(): array { return [ 'index' => Pages\ListCategories::route('/'), 'create' => Pages\CreateCategory::route('/create'),...
Jump to solution
3 Replies
S. Mert ÖZTÜRK
S. Mert ÖZTÜRK14mo ago
YourResource::getUrl('edit', ['record' => $customer]); $customer is can be model or id. This gives a edit url
Fogzy
FogzyOP14mo ago
thanks, I'm trying that, but I must be missing something. I don't have the model in this static context:
public static function getPages(): array
{
return [
'index' => Pages\ListCategories::route('/'),
'create' => Pages\CreateCategory::route('/create'),
'edit' => CategoryResource::getUrl('edit', ['record' => $dontHave]), // dont have this variable
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListCategories::route('/'),
'create' => Pages\CreateCategory::route('/create'),
'edit' => CategoryResource::getUrl('edit', ['record' => $dontHave]), // dont have this variable
];
}
Solution
mar5hall
mar5hall14mo ago
public static function getPages(): array
{
return [
'index' => Pages\ListCategories::route('/'),
'create' => Pages\CreateCategory::route('/create'),
'edit' => Pages\EditCategory::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListCategories::route('/'),
'create' => Pages\CreateCategory::route('/create'),
'edit' => Pages\EditCategory::route('/{record}/edit'),
];
}
Then for example
Tables\Actions\Action::make('edit')
->url(fn (Category $record): string => url(self::getUrl('edit', ['record' => $record])))
Tables\Actions\Action::make('edit')
->url(fn (Category $record): string => url(self::getUrl('edit', ['record' => $record])))
Want results from more Discord servers?
Add your server