Advertisement
Guest User

Untitled

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