lundi 8 février 2021

Laravel State Pattern - Where should I authenticate users?

I have an Laravel application where Im using a Service Layer Pattern. All my authorization rules are located at AuthServiceProvider using gates Ex.

...
Gate::define('can-list-products', function (User $user) {
            return $user->role == \App\Models\AuthRole::ADMIN;
        });
...

and inside my controllers I do the following:

 Gate::authorize('can-list-products');

Everything is working fine but now I have some business rules that fits in a State Pattern

Ive already created this pattern's structure but should I check for user roles inside an handle function?

I copied an image to exemplify where Im intending to check for user role. enter image description here

Aucun commentaire:

Enregistrer un commentaire