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, TeeSolution:Jump to solution
try this.
Action::make()->authorize(fn () => Auth::user()->can('view_email'))
15 Replies
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.
Is the process the same for custom made actions @awcodes ? Maybe I am not undertsanding the docs fully
the "View Email" is the custom action, I can see it in the permissions editor
I have this in the resource
but I have nothing added to the policy...
do I need to generate the policies again?
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.
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
try this.
Action::make()->authorize(fn () => Auth::user()->can('view_email'))
or whatever the actual permission name is.
that worked perfectly @awcodes however I am getting IDE (VS Code) error on
->can
no errors in runtime... 🤔
No clue about the ide error. Sorry. It certainly exists.
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 ...