dynamically hiding actions - caching issue??

Hi guys, I have a permission service which allows admins to edit certain models. I return an array of actions if canAdmin($modelClass) is true, and an empty array if false. So it seems to work and the buttons have disappeared, but upon switching back to admin, the buttons dont reappear, and indeed, upon reverting my code back to the resource with hard coded buttons still doesn't bring them back! Is there some sort of caching issue? because i was sure reverting my code would work :-p
No description
No description
Solution:
I guess you should use ->visible()/->hidden() on the Action instead
Jump to solution
9 Replies
delboy1978uk
delboy1978ukOP3mo ago
diff of the original code, which also doesn't show the buttons now
No description
delboy1978uk
delboy1978ukOP3mo ago
Ok it's ctually working perfectly on one of my other resources so it must be something particular with that resource that is the problem, thanks anyway
Solution
Dennis Koch
Dennis Koch3mo ago
I guess you should use ->visible()/->hidden() on the Action instead
Dennis Koch
Dennis Koch3mo ago
Actions are cached as far as I know
delboy1978uk
delboy1978ukOP3mo ago
ah, thanks!
Dennis Koch
Dennis Koch3mo ago
Hope that fixes your issue.
delboy1978uk
delboy1978ukOP3mo ago
because yes the one it worked perfectly on? now acting erratically
return [
CreateAction::make()->visible(self::canAdmin($modelClass)),
];
return [
CreateAction::make()->visible(self::canAdmin($modelClass)),
];
this ought to work 🙂 Thanks again!
Dennis Koch
Dennis Koch3mo ago
Great. You're welcome
delboy1978uk
delboy1978ukOP3mo ago
Thanks @Dennis Koch it worked a treat!

Did you find this page helpful?