public function hasRole($name, $group = null, $requireAll = false)
{
$requireAll = is_bool($group) ? $group : $requireAll;
$group = is_bool($group) ? null : $group;
if (is_array($name)) {
if (empty($name)) {
return true;
}
foreach ($name as $roleName) {
$hasRole = $this->hasRole($roleName, $group);
if ($hasRole && !$requireAll) {
return true;
} elseif (!$hasRole && $requireAll) {
return false;
}
}
// If we've made it this far and $requireAll is FALSE, then NONE of the roles were found
// If we've made it this far and $requireAll is TRUE, then ALL of the roles were found.
// Return the value of $requireAll;
return $requireAll;
}
if (!is_null($group)) {
$group = call_user_func_array([Config::get('laratrust.group'), 'where'], ['name', $group])->first();
$group = is_null($group) ? $group : $group->getKey();
}
foreach ($this->cachedRoles() as $role) {
if ($role->name == $name && $role->pivot->group_id == $group) {
return true;
}
}
return false;
}