Override Permissions for Super Admin

If you've defined your Gates but want to override all permissions for SUPER ADMIN user, to give that superadmin ALL permissions, you can intercept gates with Gate::before() statement, in AuthServiceProvider.php file.

1// Intercept any Gate and check if it's super admin
2Gate::before(function($user, $ability) {
3 if ($user->is_super_admin == 1) {
4 return true;
5 }
6});
7 
8// Or if you use some permissions package...
9Gate::before(function($user, $ability) {
10 if ($user->hasPermission('root')) {
11 return true;
12 }
13});

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord