Use Filament Shield to manage access to Table Actions

Hi, I did some research and some GPT prompts but found nothing useful so far... Is it possible to block / allow access to Table Actions using Filament Shield? Or will it be better to use ->visible() Cheers, Tee
Solution:
try this. Action::make()->authorize(fn () => Auth::user()->can('view_email'))
Jump to solution
15 Replies
awcodes
awcodes5mo ago
The actions are tired to the policy. Ie, if the user can’t delete records then the delete action won’t show. Make sure you generated the policy via shield. It’s covered the the shield readme.
TheRealTeeHill
TheRealTeeHillOP5mo ago
Is the process the same for custom made actions @awcodes ? Maybe I am not undertsanding the docs fully
TheRealTeeHill
TheRealTeeHillOP5mo ago
No description
TheRealTeeHill
TheRealTeeHillOP5mo ago
the "View Email" is the custom action, I can see it in the permissions editor I have this in the resource
TheRealTeeHill
TheRealTeeHillOP5mo ago
No description
TheRealTeeHill
TheRealTeeHillOP5mo ago
but I have nothing added to the policy... do I need to generate the policies again?
awcodes
awcodes5mo ago
generating policies, doesn't handle custom authorizations. For custom actions you will need to add additional methods to the policy and handle the authorizations inside your custom action that check against that policy method. if that makes sense. in this case though, since you likely don't need this authorization anywhere else you can authorize on the action itself without the policy.
TheRealTeeHill
TheRealTeeHillOP5mo ago
correct the action I am working on only exists in 1 resorce, I have a meeting to attend, I will attempt some things when I finish, cheers for the help/info so far ❤️
Solution
awcodes
awcodes5mo ago
try this. Action::make()->authorize(fn () => Auth::user()->can('view_email'))
awcodes
awcodes5mo ago
or whatever the actual permission name is.
TheRealTeeHill
TheRealTeeHillOP5mo ago
that worked perfectly @awcodes however I am getting IDE (VS Code) error on ->can
TheRealTeeHill
TheRealTeeHillOP5mo ago
No description
TheRealTeeHill
TheRealTeeHillOP5mo ago
no errors in runtime... 🤔
awcodes
awcodes5mo ago
No clue about the ide error. Sorry. It certainly exists.
TheRealTeeHill
TheRealTeeHillOP5mo ago
https://github.com/bmewburn/vscode-intelephense/issues/1223 seems I'm not the only one and issue is unrelated to the answer you gave, cheers
GitHub
Undefined Laravel User 'Can' method · Issue #1223 · bmewburn/vscode...
Describe the bug I'm using Laravel and its authorization feature using policy and it's showing me that method can on auth user is not defined even it is. The script is running fine without ...
Want results from more Discord servers?
Add your server