F
Filamentβ€’10mo ago
Anik

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. 😒
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
// error from navigationItem::url() on being included here
])
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
// error from navigationItem::url() on being included here
])
}
trying to override NavigationItem gives the error https://flareapp.io/share/Vme190qm
public static function getNavigationItems(array $urlParameters = []): array

{

return [

NavigationItem::make(static::getNavigationLabel())

->group(static::getNavigationGroup())

->parentItem(static::getNavigationParentItem())

->icon(static::getNavigationIcon())

->activeIcon(static::getActiveNavigationIcon())

// ->isActiveWhen(fn (): bool => request()->routeIs(static::getRouteName()))

->sort(static::getNavigationSort())

->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())

->url(fn (): string => EventsResource::getUrl('bookings.index', ['parent' => $this->parent])),

];
}
public static function getNavigationItems(array $urlParameters = []): array

{

return [

NavigationItem::make(static::getNavigationLabel())

->group(static::getNavigationGroup())

->parentItem(static::getNavigationParentItem())

->icon(static::getNavigationIcon())

->activeIcon(static::getActiveNavigationIcon())

// ->isActiveWhen(fn (): bool => request()->routeIs(static::getRouteName()))

->sort(static::getNavigationSort())

->badge(static::getNavigationBadge(), color: static::getNavigationBadgeColor())

->url(fn (): string => EventsResource::getUrl('bookings.index', ['parent' => $this->parent])),

];
}
2 Replies
Anik
AnikOPβ€’10mo ago
bump
Tim
Timβ€’5mo ago
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!

Did you find this page helpful?