You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/basic-usage/super-admin.md
+12-15
Original file line number
Diff line number
Diff line change
@@ -11,21 +11,18 @@ Then you can implement the best-practice of primarily using permission-based con
11
11
## `Gate::before`
12
12
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:
13
13
14
+
In Laravel 11 this would go in the `boot()` method of `AppServiceProvider`:
15
+
In Laravel 10 and below it would go in the `boot()` method of `AuthServiceProvider.php`:
14
16
```php
15
17
use Illuminate\Support\Facades\Gate;
16
-
17
-
class AuthServiceProvider extends ServiceProvider
18
+
// ...
19
+
public function boot()
18
20
{
19
-
public function boot()
20
-
{
21
-
//...
22
-
23
-
// Implicitly grant "Super Admin" role all permissions
24
-
// This works in the app by using gate-related functions like auth()->user->can() and @can()
@@ -37,11 +34,11 @@ Jeffrey Way explains the concept of a super-admin (and a model owner, and model
37
34
38
35
If you aren't using `Gate::before()` as described above, you could alternatively grant super-admin control by checking the role in individual Policy classes, using the `before()` method.
39
36
40
-
Here is an example from the [Laravel Documentation on Policy Filters](https://laravel.com/docs/master/authorization#policy-filters)
37
+
Here is an example from the [Laravel Documentation on Policy Filters](https://laravel.com/docs/master/authorization#policy-filters), where you can define `before()` in your Policy where needed:
41
38
42
39
```php
43
-
use App\Models\User; // could be any model
44
-
40
+
use App\Models\User; // could be any Authorizable model
Copy file name to clipboardExpand all lines: docs/best-practices/using-policies.md
+61-1
Original file line number
Diff line number
Diff line change
@@ -9,4 +9,64 @@ Using Policies allows you to simplify things by abstracting your "control" rules
9
9
10
10
Jeffrey Way explains the concept simply in the [Laravel 6 Authorization Filters](https://laracasts.com/series/laravel-6-from-scratch/episodes/51) and [policies](https://laracasts.com/series/laravel-6-from-scratch/episodes/63) videos and in other related lessons in that chapter. He also mentions how to set up a super-admin, both in a model policy and globally in your application.
11
11
12
-
You can find an example of implementing a model policy with this Laravel Permissions package in this demo app: [https://github.com/drbyte/spatie-permissions-demo/blob/master/app/Policies/PostPolicy.php](https://github.com/drbyte/spatie-permissions-demo/blob/master/app/Policies/PostPolicy.php)
12
+
Here's an example of a PostPolicy which could control access to Post model records:
0 commit comments