View difference between Paste ID: DmCZEP4C and je1NYzQb
SHOW: | | - or go back to the newest paste.
1
public function roles()
2-
	public function is($roles = array())
2+
{
3-
	{
3+
	return $this->belongsToMany("Role");
4-
		if(!is_array($roles))
4+
}
5-
			$roles = array($roles);
5+
6
// boolean function to test for roles a user belongs to
7-
		$user_permissions = array_pluck($this->roles()->get()->toArray(), "name");
7+
public function is($roles = array())
8
{
9-
		// make sure that the number of intersections is the same as the number of roles.
9+
	if(!is_array($roles))
10-
		// this returns the answer to "can user do all the above?"
10+
		$roles = array($roles);
11
	
12-
		return ( count( array_intersect($roles, $user_permissions) ) === count($roles) );
12+
	$user_permissions = array_pluck($this->roles()->get()->toArray(), "name");
13-
	}
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
}