Skip to content

Commit

Permalink
[Docs] sync relevant parts with v6
Browse files Browse the repository at this point in the history
  • Loading branch information
drbyte committed Oct 13, 2023
1 parent f114682 commit c26ad91
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/advanced-usage/ui-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ weight: 11

The package doesn't come with any screens out of the box, you should build that yourself. Here are some options to get you started:

- [Code With Tony - video series](https://www.youtube.com/watch?v=lGfV1ddMhHA) to create an admin panel for managing roles and permissions in Laravel 9.

- [FilamentPHP plugin](https://filamentphp.com/plugins/tharinda-rodrigo-spatie-roles-permissions) to manage roles and permissions using this package.

- If you'd like to build your own UI, and understand the underlying logic for Gates and Roles and Users, the [Laravel 6 User Login and Management With Roles](https://www.youtube.com/watch?v=7PpJsho5aak&list=PLxFwlLOncxFLazmEPiB4N0iYc3Dwst6m4) video series by Mark Twigg of Penguin Digital gives thorough coverage to the topic, the theory, and implementation of a basic Roles system, independent of this Permissions Package.

- [Laravel Nova package by @vyuldashev for managing Roles and Permissions](https://github.com/vyuldashev/nova-permission)
Expand Down
27 changes: 24 additions & 3 deletions docs/basic-usage/super-admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ weight: 8

We strongly recommend that a Super-Admin be handled by setting a global `Gate::before` or `Gate::after` rule which checks for the desired role.

Then you can implement the best-practice of primarily using permission-based controls (@can and $user->can, etc) throughout your app, without always having to check for "is this a super-admin" everywhere. Best not to use role-checking (ie: `hasRole`) when you have Super Admin features like this.
Then you can implement the best-practice of primarily using permission-based controls (@can and $user->can, etc) throughout your app, without always having to check for "is this a super-admin" everywhere. **Best not to use role-checking (ie: `hasRole`) (except here in Gate/Policy rules) when you have Super Admin features like this.**


## `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. 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:

```php
use Illuminate\Support\Facades\Gate;
Expand All @@ -33,12 +33,33 @@ NOTE: `Gate::before` rules need to return `null` rather than `false`, else it wi

Jeffrey Way explains the concept of a super-admin (and a model owner, and model policies) in the [Laravel 6 Authorization Filters](https://laracasts.com/series/laravel-6-from-scratch/episodes/51) video and some related lessons in that chapter.

## Policy `before()`

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.

Here is an example from the [Laravel Documentation on Policy Filters](https://laravel.com/docs/master/authorization#policy-filters)

```php
use App\Models\User; // could be any model

/**
* Perform pre-authorization checks on the model.
*/
public function before(User $user, string $ability): bool|null
{
if ($user->hasRole('Super Admin') {
return true;
}

return null; // see the note above in Gate::before about why null must be returned here.
}
```

## `Gate::after`

Alternatively you might want to move the Super Admin check to the `Gate::after` phase instead, particularly if your Super Admin shouldn't be allowed to do things your app doesn't want "anyone" to do, such as writing more than 1 review, or bypassing unsubscribe rules, etc.

The following code snippet is inspired from [Freek's blog article](https://freek.dev/1325-when-to-use-gateafter-in-laravel) where this topic is discussed further.
The following code snippet is inspired from [Freek's blog article](https://freek.dev/1325-when-to-use-gateafter-in-laravel) where this topic is discussed further. You can also consult the [Laravel Docs on gate interceptions](https://laravel.com/docs/master/authorization#intercepting-gate-checks)

```php
// somewhere in a service provider
Expand Down
6 changes: 4 additions & 2 deletions docs/installation-lumen.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ title: Installation in Lumen
weight: 5
---

NOTE: Lumen is **not** officially supported by this package. However, the following are some steps which may help get you started.
NOTE: Lumen is **not** officially supported by this package. And Lumen is no longer under active development.

Lumen installation instructions can be found in the [Lumen documentation](https://lumen.laravel.com/docs/main).
However, the following are some steps which may help get you started.

Lumen installation instructions can be found in the [Lumen documentation](https://lumen.laravel.com/docs/master).

## Installing

Expand Down

0 comments on commit c26ad91

Please sign in to comment.