How to Hide Panel Icons Based on User Roles and Order Panels
I'm working on a Laravel Filament project with multiple panels, and I need to customize the visibility of these panels based on user roles. Specifically, I want to:
Hide panel icons if a user’s role doesn’t have access to that panel.
Maintain a specific order for the panel display.(admin, doctorants,.)
Here’s my current setup:
I'm using the bezhansalleh/filament-shield package for role management.
Each user can have access to multiple panels, and I store panel access information in a panel_accesses table, which associates roles with panel IDs.
Could anyone please provide guidance or examples on how to achieve this? Any help would be greatly appreciated!
Solution:Jump to solution
Finally: ),
The solution was to use the excludes() method,
https://filamentphp.com/plugins/bezhansalleh-panel-switch#panel-exclusion
AppServiceProvider:
...
7 Replies
Maybe I’m just not getting it, but why would the icon for a model/resource ever be different?
Like, an icon represents a thing, does the permissions change the context of the thing?
Hi, The icon of a panel represents its resources. I want to hide entire panel (including the icon) if a user’s role doesn’t have access to that panel. The goal is to control visibility dynamically based on user roles.
Sounds like you need specific panels.
And middle ware to direct the user on login. But I still don’t understand the use case. Sorry.
sorry ,
example:
super-admin can have access to all panels (can switch all panel)
establishment can have access to only 3 panels, but I do not want him to see the other panels that he does not have access to, knowing that when he clicks on a panel that he does not have authorization it displays 403 forbidden
White image=> super admin
Black image>. establishment
Can probably wrap them in @can() directive and hide them based on the user role.
I guess this is a question for #bezhansalleh-panel-switch
Solution
Finally: ),
The solution was to use the excludes() method,
https://filamentphp.com/plugins/bezhansalleh-panel-switch#panel-exclusion
AppServiceProvider:
User:
PanelAccess
Thank you! 🙏 :fi: