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