navigationitems override
Hello, I want to modify the url() in the navigationItem for a page class. right now they are set to static and cannot be overridden in a ListRecord class. I am trying to get Nested resource from this tutorial.
https://laraveldaily.com/post/filament-v3-nested-resources-trait-pages
The list page works as in the tutorial but when I use it with getRecordSubNavigation, it gives this error.
https://flareapp.io/share/LPdK90Qm
Kindly help. π’
trying to override NavigationItem gives the error
https://flareapp.io/share/Vme190qm
2 Replies
bump
I was struggling with the same thing, but I realised (after quite a bit of time π€¦ββοΈ ) I could just pass the NavigationItem array directly from the getRecordSubNavigation, and the URL would be taken in to account.
If you actually need the results from $page->generateNavigationItems then you can't do this, but otherwise you can potentially just pass the NavigationItems you need without using the $page->generateNavigationItems
This is what I did directly in the getRecordSubNavigation for a "parent" resource of "Event" (ie in the EventResource) and a "child" resource of "Session":
public static function getRecordSubNavigation(Page $page): array
{
return [
NavigationItem::make('Event Details')
->url(fn (): string => EventResource\Pages\EditEvent::getUrl(['record' => request('record')]))
->isActiveWhen(fn () => Route::currentRouteName() === 'filament.app.resources.events.edit'),
NavigationItem::make('Sessions')
->url(fn (): string => EventResource::getUrl('sessions.index', ['parent' => request('record')]))
->isActiveWhen(fn () => Route::is('filament.app.resources.events.sessions*'))
];
}
Please note that the URL to access the child resource needs to come from the parent resource (as in Anik's original question), ie EventResource::getUrl('sessions.index', ['parent' => request('record')]).
I literally love the flexibility and functionality of filament! Hopefully I am not encouraging people to use it in the wrong way!