authorization in NavigationItem
I have this in my
AppServiceProvider
class:
Based on the documentation, it indicates I can add a NavigationItem and conditionally show/hide it based on the role of the user. However, I believe that at this point in the execution, the app is still booting and the authorized user isn't available. I'm getting an error that I can't call can()
on null.3 Replies
maybe I need to add a method to my
UserResource
and RoleResource
classes? https://filamentphp.com/docs/3.x/panels/pages#conditionally-hiding-pages-in-navigationTry it in a callback. visible(fn() => auth->can)
that didn't work either...the link I posted seems to be the way to do it, but that method returns false when it shouldn't, and when I
dd()
inside of my policy, it's not even hitting the policy at all.
In my UserResource
:
It works if I don't use the policy and I just do something like: return auth()->user()->hasRole('System Admin');
in the shouldRegisterNavigation
method.
so it seems to be policy related.