Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function roles()
- {
- return $this->belongsToMany("Role");
- }
- // boolean function to test for roles a user belongs to
- public function is($roles = array())
- {
- if(!is_array($roles))
- $roles = array($roles);
- $user_permissions = array_pluck($this->roles()->get()->toArray(), "name");
- // make sure that the number of intersections is the same as the number of roles.
- // this returns the answer to "can user do all the above?"
- return ( count( array_intersect($roles, $user_permissions) ) === count($roles) );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement