Silber\Bouncer\Clipboard::checkRole PHP Method

checkRole() public method

Check if an authority has the given roles.
public checkRole ( Model $authority, array | string $roles, string $boolean = 'or' ) : boolean
$authority Illuminate\Database\Eloquent\Model
$roles array | string
$boolean string
return boolean
    public function checkRole(Model $authority, $roles, $boolean = 'or')
    {
        $available = $this->getRoles($authority)->intersect($roles);
        if ($boolean == 'or') {
            return $available->count() > 0;
        } elseif ($boolean === 'not') {
            return $available->count() === 0;
        }
        return $available->count() == count((array) $roles);
    }

Usage Example

Example #1
0
 /**
  * Check if the user has all of the given roles.
  *
  * @param  string  $role
  * @return bool
  */
 public function all($role)
 {
     $roles = func_get_args();
     return $this->clipboard->checkRole($this->user, $roles, 'and');
 }