Laravel-5 adding hasRole method to Auth

前端 未结 3 1425
情话喂你
情话喂你 2021-02-06 16:03

I\'m trying to extend the Laravel-5.1 Auth middleware so that I can add my own method to it:

Auth::hasRole()

What do I need to do in or

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 16:35

    I've taken a different tack by using a trait in my User model.

    belongsToMany('App\Role');
        }
    
        public static function findByRole(Role $role)
        {
            return $role->users()->get();
        }
    
        public function hasRole(Role $role)
        {
            return $this->roles()->get()->contains($role);
        }
    }
    

提交回复
热议问题