F
Filament10mo ago
Wirkhof

How to grab user's roles in Filament?

I am using Filament Shield and I have assigned a role panel_role to a user. I want to limit the visibility of a certain form field based on the role of the current user. For a specific user id (in this case if the user has id 39), this works:
->visible(fn () => auth()->id() === 39)
->visible(fn () => auth()->id() === 39)
And only the user with id 39 sees that form field. But how to do a condition targeting user's role? how would the visible method look like in that case? Let's say for the panel_role?
Solution:
Solved it myself
Jump to solution
2 Replies
Solution
Wirkhof
Wirkhof10mo ago
Solved it myself
Wirkhof
WirkhofOP10mo ago
auth()->user()->hasRole('panel_role') === 1
Want results from more Discord servers?
Add your server