F
Filament3mo ago
harumi

dynamic index route

how to make the index route that accessed like dashboard/action/{record} on the TransactionResource class i set the pages like this
public static function getPages(): array
{
return [
'index' => Pages\ListTransactions::route('/{record}'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListTransactions::route('/{record}'),
];
}
it getting error like this when i access /dashboard/action/test
Missing required parameter for [Route: filament.admin.resources.action.index] [URI: dashboard/action/{record}] [Missing parameter: record].
Missing required parameter for [Route: filament.admin.resources.action.index] [URI: dashboard/action/{record}] [Missing parameter: record].
it work when i set 2 route like
'index' => Pages\ListTransactions::route('/'),
'index2' => Pages\ListTransactions::route('/{record}'),
'index' => Pages\ListTransactions::route('/'),
'index2' => Pages\ListTransactions::route('/{record}'),
but i dont want to add the / route how to fix that?
Solution:
i think something like this is work for me ```php public function getBreadcrumbs(): array { return [...
Jump to solution
9 Replies
Dennis Koch
Dennis Koch3mo ago
The error probably comes when the navigation items are registered, since Filament doesn't expect a new param You can overwrite the navigation items via getNavigationItems() method.
harumi
harumiOP3mo ago
I have declared the getNavigationItems method like this
public static function getNavigationItems(): array
{
return [
// mock get data from db
NavigationItem::make()
->label('Testing')
->icon('heroicon-o-rectangle-stack')
->url('/dashboard/action/name')
->isActiveWhen(function (): bool {
return request()->is('dashboard/action/name*');
}),
];
}
public static function getNavigationItems(): array
{
return [
// mock get data from db
NavigationItem::make()
->label('Testing')
->icon('heroicon-o-rectangle-stack')
->url('/dashboard/action/name')
->isActiveWhen(function (): bool {
return request()->is('dashboard/action/name*');
}),
];
}
Dennis Koch
Dennis Koch3mo ago
I think you also need to overwrite the getBreadcrumbs() one.
harumi
harumiOP3mo ago
do you have documentation for that? i have override the getBreadcrumbs method like this
public static function getBreadcrumbs(): array
{
return [];
}
public static function getBreadcrumbs(): array
{
return [];
}
it's getting error like this
Cannot redeclare App\Filament\Resources\TransactionResource::getBreadcrumbs()
Cannot redeclare App\Filament\Resources\TransactionResource::getBreadcrumbs()
Dennis Koch
Dennis Koch3mo ago
No, you need to check the source code. Is this the complete error? Seems like there is some part missing. Redeclare usually means, you didn't specify the method the same as before.
harumi
harumiOP3mo ago
where should i override the getBreadcrumbs? on resource class or on page class? yeah that all the error
Solution
harumi
harumi3mo ago
i think something like this is work for me
public function getBreadcrumbs(): array
{
return [
url()->current() => static::$breadcrumb ?? static::getTitle(),
0 => request()->route('resource'),
];
}
public function getBreadcrumbs(): array
{
return [
url()->current() => static::$breadcrumb ?? static::getTitle(),
0 => request()->route('resource'),
];
}
i override the getBreadcrumbs method from the ListTransactions class this is correct?
Dennis Koch
Dennis Koch3mo ago
If it works for you and you don't get an error, it seems correct 😉
harumi
harumiOP3mo ago
i think it should be fine 🙂 , thanks for the help

Did you find this page helpful?