dimanche 16 février 2020

Laravel Gate::any() returns reverted value

I am defining gate in my code like this

    Gate::define('fullAccess',function ($user){
        return $user->id == 1;
    });
    Gate::define('manager',function ($user){
        return $user->type == User::TYPE_MANAGER;
    });

then in contoller I am checking if user has access

 public function __construct()
 {
     if(!Gate::any(['fullAccess','manager'])){
         abort(403);
     }
 }

But there is a problem:

 if(!Gate::any(['fullAccess','manager'])){
     //returns true
 }
 if(Gate::any(['fullAccess','manager'])){
     //returns false
 }

I'm absolutly sure my ID equals 1, and I think any() function must return true if at least one access action is available for curent user. Am I missing something?

I've tried none function also, and it works the same way

 if(Gate::none(['fullAccess','manager'])){
    //returns true;
 }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3bH4vcX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire