Laratrust\Traits\LaratrustRoleTrait::hasPermission PHP Method

hasPermission() public method

Checks if the role has a permission by its name.
public hasPermission ( string | array $name, boolean $requireAll = false ) : boolean
$name string | array Permission name or array of permission names.
$requireAll boolean All permissions in the array are required.
return boolean
    public function hasPermission($name, $requireAll = false)
    {
        if (is_array($name)) {
            foreach ($name as $permissionName) {
                $hasPermission = $this->hasPermission($permissionName);
                if ($hasPermission && !$requireAll) {
                    return true;
                } elseif (!$hasPermission && $requireAll) {
                    return false;
                }
            }
            // If we've made it this far and $requireAll is FALSE, then NONE of the permissions were found
            // If we've made it this far and $requireAll is TRUE, then ALL of the permissions were found.
            // Return the value of $requireAll;
            return $requireAll;
        }
        foreach ($this->cachedPermissions() as $permission) {
            if ($permission->name == $name) {
                return true;
            }
        }
        return false;
    }