arrow_back How do I write gates compactly in Laravel?

2 votes
I use gates to check the permissions. If you define each permission this way, you get a big function. How can I avoid it?
public function boot()

Gate::define('users_info', function ($admin) {
if (! $admin->hasPermission('users_info') ) {
throw new AccessDenyException(ErrorMessages::ACCESS_DENIED, Response::HTTP_FORBIDDEN);

return true;


Start using policies?
JhaoDa I don't know why I'm stuck with gates, it's really better to use them, thanks.

1 Answer

0 votes
There are ready-made packages. Why all this misery?


Sanes I don't need those tables, just a table with permissions and one summary. The haspermission method and the policy that calls it. Used to use entrust, wouldn't say there's less to write
These packages create several tables in the database and add a bunch of code, and so I added the hasPermission method for the model and call it in the policy.
Eugene , they create it because you have to store it somewhere.
Eugene I don't need it right now. I use laravel-permission. You can disable permissions and leave only roles.