This repository was archived by the owner on Jan 29, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 54
Admin permission Grant all access to a user
Mateus Junges edited this page May 26, 2019
·
3 revisions
You may provide a super-admin permission or group for users who might have totally access to your application.
But, add all the system permissions to a admin role is time consuming and laborious.
If you want the admin GROUP to allow full access without having to add all system permissions to it, you may use the before method to define a callback that is run before all other authorization checks:
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
public function boot()
{
$this->registerPolicies();
Gate::before(function ($user, $ability) {
return $user->hasGroup('admin') ? true : null;
});
}
}If you want the admin PERMISSION to allow full access, you may use the before method to define a callback that is run before all other authorization checks:
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
public function boot()
{
$this->registerPolicies();
Gate::before(function ($user, $ability) {
return $user->hasPermission('admin') ? true : null;
});
}
}If the before callback returns a non-null result that result will be considered the result of the check.