From 839b77427bfb45d6e6870d90c453acc906cd4218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20H=2E?= <36476318+Tamas-hi@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:20:34 +0200 Subject: [PATCH] Update super-admin.md 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. --- docs/basic-usage/super-admin.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/basic-usage/super-admin.md b/docs/basic-usage/super-admin.md index 4eefee99..190df715 100644 --- a/docs/basic-usage/super-admin.md +++ b/docs/basic-usage/super-admin.md @@ -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`: @@ -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; }); } ``` @@ -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; } @@ -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 }); ```