Conditionally show a dashboard page
I only want to have certain user roles have a dashboard, but the user is not resolved yet in the panel's provider. Is there any way to just hide a dashboard via policies for example, just like how I can hide a resource for certain users?
14 Replies
Might be a little messy, but all that
->pages
needs is an array. You could create the array before return $panel
with conditional logic and then use ->pages($pagesArray)
The thing that I need to create such array (the authenticated user in this case, to check his role) is unfortunately not resolved at that point.
maybe create your own dashboard and in the mount if can't access redirect somewhere else. should be doable i believe
Hmm, I guess that in combination with setting
shouldRegisterNavigation()
should work. Still feels hacky, but workswouldn't say it's hacky
What do you mean by not resolved? Do you mean the user hasn't been ceated yet? Or is there no access to
auth()->user()
in the panel provider?Service providers are ran before the session is initiated so there is no authenticated user at that point.
I think there might be a bug too. $panel->bootUsing() should have access to the user, but Iβm getting null for the user in my tests. π€
any solution for version 2?
Yes. Upgrade to v3 π
tell that my customer π
Tell him other way it's not possible
Or there was I think some package
Other way to hide just widgets if user doesn't have access
The panel initialisation is triggered from the register method of the laravel provider. Since the user is established in the middleware pipeline, it is not available.
I would solve this with a custom middleware (which can be added in the panel construction).