F
Filamentβ€’8mo ago
Alexandre

How to put the resource creation link in the navigation of the panel?

Hey folks πŸ‘‹ I've created a panel for users and I have a RequestResource (with default pages). My resource registers well in the navigation (the page to display all Requests but I would also like a direct link to create a Request in my navigation. Is there an easy way to do this? I've tried adding navigation-related statics properties to the App\Filament\User\Resources\RequestResource\CreateRequest.php page (like $navigationIcon, $navigationGroup, etc.) but it doesn't seem to work. So I tried going through the UserPanelProdiver file and adding this method:
->navigationItems(
[
NavigationItem::make( 'create_request' )
->label( __( 'users/requests.navigation_create_label' ) )
->group( __( 'users/requests.navigation_group' ) )
->url( '/requests/create' )
->icon( 'heroicon-o-plus' ),
]
)
->navigationItems(
[
NavigationItem::make( 'create_request' )
->label( __( 'users/requests.navigation_create_label' ) )
->group( __( 'users/requests.navigation_group' ) )
->url( '/requests/create' )
->icon( 'heroicon-o-plus' ),
]
)
It works, but I don't know how to manage the active class πŸ˜… Can anyone shed some light on this? Thanks in advance πŸ˜‡
Solution:
You could try something along those lines: ```php NavigationItem::make('New Request') ->label(__( 'users/requests.navigation_create_label' ))...
Jump to solution
2 Replies
Solution
dissto
disstoβ€’8mo ago
You could try something along those lines:
NavigationItem::make('New Request')
->label(__( 'users/requests.navigation_create_label' ))
->group(__( 'users/requests.navigation_group' ))
->icon('heroicon-o-plus')
->url(fn () => Pages\CreateRequest::getUrl())
->isActiveWhen(fn () => request()->routeIs(Pages\CreateRequest::getRouteName())),
NavigationItem::make('New Request')
->label(__( 'users/requests.navigation_create_label' ))
->group(__( 'users/requests.navigation_group' ))
->icon('heroicon-o-plus')
->url(fn () => Pages\CreateRequest::getUrl())
->isActiveWhen(fn () => request()->routeIs(Pages\CreateRequest::getRouteName())),
Alexandre
AlexandreOPβ€’8mo ago
Hey, great it's working thanks ! But it's weird because the active class was also set to the "All requests" item (generated via the RequestResource" class). So I added this to RequestResource.php:
protected static bool $shouldRegisterNavigation = false;
protected static bool $shouldRegisterNavigation = false;
And add a new Item in my navigation for the ListRequest :
->navigationItems(
[
NavigationItem::make( 'New request' )
->label( __( 'users/requests.create.navigation_label' ) )
->group( __( 'users/requests.navigation_group' ) )
->url(fn () => CreateRequest::getUrl())
->icon( 'heroicon-o-plus' )
->isActiveWhen(fn () => request()->routeIs(CreateRequest::getRouteName())),
NavigationItem::make( 'See requests' )
->label( __( 'users/requests.all.navigation_label' ) )
->group( __( 'users/requests.navigation_group' ) )
->url(fn () => ListRequests::getUrl())
->icon( 'heroicon-o-eye' )
->isActiveWhen(fn () => request()->routeIs(ListRequests::getRouteName())),
]
)
->navigationItems(
[
NavigationItem::make( 'New request' )
->label( __( 'users/requests.create.navigation_label' ) )
->group( __( 'users/requests.navigation_group' ) )
->url(fn () => CreateRequest::getUrl())
->icon( 'heroicon-o-plus' )
->isActiveWhen(fn () => request()->routeIs(CreateRequest::getRouteName())),
NavigationItem::make( 'See requests' )
->label( __( 'users/requests.all.navigation_label' ) )
->group( __( 'users/requests.navigation_group' ) )
->url(fn () => ListRequests::getUrl())
->icon( 'heroicon-o-eye' )
->isActiveWhen(fn () => request()->routeIs(ListRequests::getRouteName())),
]
)
So now it's good. Thanks for your help πŸ˜ƒ
Want results from more Discord servers?
Add your server