Advertisement
Guest User

Role Check function for User Model

a guest
Jun 12th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. // boolean function to test for roles a user belongs to
  2.     public function is($roles = array())
  3.     {
  4.         if(!is_array($roles))
  5.             $roles = array($roles);
  6.        
  7.         $user_permissions = array_pluck($this->roles()->get()->toArray(), "name");
  8.        
  9.         // make sure that the number of intersections is the same as the number of roles.
  10.         // this returns the answer to "can user do all the above?"
  11.        
  12.         return ( count( array_intersect($roles, $user_permissions) ) === count($roles) );
  13.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement