F
Filamentβ€’14mo ago
Arko

Conditionally show a dashboard page

return $panel
->pages([
Pages\Dashboard::class,
]);
return $panel
->pages([
Pages\Dashboard::class,
]);
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
bwurtz999
bwurtz999β€’14mo ago
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)
Arko
ArkoOPβ€’14mo ago
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.
krekas
krekasβ€’14mo ago
maybe create your own dashboard and in the mount if can't access redirect somewhere else. should be doable i believe
Arko
ArkoOPβ€’14mo ago
Hmm, I guess that in combination with setting shouldRegisterNavigation() should work. Still feels hacky, but works
krekas
krekasβ€’14mo ago
wouldn't say it's hacky
bwurtz999
bwurtz999β€’14mo ago
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?
Arko
ArkoOPβ€’14mo ago
Service providers are ran before the session is initiated so there is no authenticated user at that point.
awcodes
awcodesβ€’14mo ago
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. πŸ€”
Falk Maria Zeitsprung
Falk Maria Zeitsprungβ€’14mo ago
any solution for version 2?
krekas
krekasβ€’14mo ago
Yes. Upgrade to v3 πŸ˜„
Falk Maria Zeitsprung
Falk Maria Zeitsprungβ€’14mo ago
tell that my customer πŸ™‚
krekas
krekasβ€’14mo ago
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
Luc Van Keer
Luc Van Keerβ€’14mo ago
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).
Want results from more Discord servers?
Add your server