islamrumon/laravel-acl
Laravel ACL provides database-backed roles, groups, and permissions for Laravel 5.8+. Note: unmaintained since Jan 2024; consider spatie/laravel-permission instead.
To add a super admin to your system, you should use the global Gate::before or Gate::after rules.
Then you can just use the permission-based controls in your application, without always checking for isAdmin or anything else everywhere
Gate::beforeIf you want your super admin to return true for all permissions checking without assigning all permissions to that user, you should use the
laravel default Gate::before method.
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
public function boot()
{
$this->registerPolicies();
Gate::before(fn ($user, $ability) => $user->hasGroup('Super Admin') ? true : null);
}
}
The closure passed to Gate::before will be used before any policy gets called.
The Gate::before method needs to return null instead of false in order to not interfere with normal policy operations.
Gate::afterWith Gate::after instead of Gate::before, the policies will be called first, even for superadmins.
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
public function boot()
{
$this->registerPolicies();
Gate::after(fn ($user, $ability) => $user->hasGroup('Super Admin'));
}
}
How can I help you explore Laravel packages today?