Skip to content

Commit

Permalink
Update super-admin.md
Browse files Browse the repository at this point in the history
As a first time reader of the package documentation (which by the way is really good!), I realized that in the seeding example we use 'super-admin'.  I haven't tried it yet, but I believe these two should be consistent to work, so I propose we change it here to super-admin as well.
  • Loading branch information
Tamas-hi authored Aug 22, 2024
1 parent 231530a commit 839b774
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/basic-usage/super-admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Then you can implement the best-practice of primarily using permission-based con


## `Gate::before`
If you want a "Super Admin" role to respond `true` to all permissions, without needing to assign all those permissions to a role, you can use [Laravel's `Gate::before()` method](https://laravel.com/docs/master/authorization#intercepting-gate-checks). For example:
If you want a "super-admin" role to respond `true` to all permissions, without needing to assign all those permissions to a role, you can use [Laravel's `Gate::before()` method](https://laravel.com/docs/master/authorization#intercepting-gate-checks). For example:

In Laravel 11 this would go in the `boot()` method of `AppServiceProvider`:
In Laravel 10 and below it would go in the `boot()` method of `AuthServiceProvider.php`:
Expand All @@ -18,10 +18,10 @@ use Illuminate\Support\Facades\Gate;
// ...
public function boot()
{
// Implicitly grant "Super Admin" role all permissions
// Implicitly grant "super-admin" role all permissions
// This works in the app by using gate-related functions like auth()->user->can() and @can()
Gate::before(function ($user, $ability) {
return $user->hasRole('Super Admin') ? true : null;
return $user->hasRole('super-admin') ? true : null;
});
}
```
Expand All @@ -44,7 +44,7 @@ use App\Models\User; // could be any Authorizable model
*/
public function before(User $user, string $ability): bool|null
{
if ($user->hasRole('Super Admin')) {
if ($user->hasRole('super-admin')) {
return true;
}

Expand All @@ -62,6 +62,6 @@ The following code snippet is inspired from [Freek's blog article](https://freek
// somewhere in a service provider

Gate::after(function ($user, $ability) {
return $user->hasRole('Super Admin'); // note this returns boolean
return $user->hasRole('super-admin'); // note this returns boolean
});
```

0 comments on commit 839b774

Please sign in to comment.