Resource Page navigation items with Proper Policies

Hello,
I am looking into improving the navigation on an application build with Filament. I know this was discussed before, but my flavor of issue includes the policies.
Here is my Panel provider, navigationItems part
  ->navigationGroups([
      NavigationGroup::make()->label('GDPR'),
  ])
  ->navigationItems([
      NavigationItem::make('Sign')
          ->url(fn() => GdprRequestResource::getUrl('create'))
          ->isActiveWhen(fn() => request()->routeIs(
              GdprRequestResource\Pages\CreateGdprRequest::getRouteName('dashboard')
          ))
          ->group('GDPR')
          ->sort(1)
          ->visible(fn() => auth()->user()->can('create', GdprRequest::class)),
      NavigationItem::make('View all')
          ->url(fn() => GdprRequestResource::getUrl('index'))
          ->isActiveWhen(fn() => request()->routeIs(
              GdprRequestResource\Pages\ListGdprRequests::getRouteName('dashboard'),
              GdprRequestResource\Pages\ViewGdprRequest::getRouteName('dashboard'),
          ))
          ->group('GDPR')
          ->sort(2)
          ->visible(fn() => auth()->user()->can('viewAny', GdprRequest::class)),
  ])


The idea is to have in the navigation a group, in this example is called GDPR and in that group at least 2 items. for this nav group: Sign and View all.
  • Problem 1: I cannot find a better way to include the CREATE page into navigation other then a custom nav item
  • Problem 2: If i add the create page into the navigation and assign the isActivWhen as in example, the default ResourceList nav is active when the create is active so i need to use a custom nav item for this also
  • Problem 3. Now that i use custom nav items i lost the default Policy check and have to use the visible method
Everything works as expected but i don`t feel this this is the best version. What happens when i add additional pages to that resource, have to update the isActiveWhen also.
Does anybody have a better implementation for this?
Was this page helpful?