App\Traits\UserHasPermissionsTrait::can PHP 메소드

can() 공개 메소드

..), first checks if the permission(s) are directly associated to the user model, using ->hasPermission(), then may if required check if permission(s) are associated through the roles, using ->canInRole().
public can ( $permission, boolean $requireAll = false ) : boolean
$permission
$requireAll boolean
리턴 boolean
    public function can($permission, $requireAll = false)
    {
        if (is_array($permission)) {
            foreach ($permission as $permName) {
                $hasPerm = $this->can($permName);
                if ($hasPerm && !$requireAll) {
                    return true;
                } elseif (!$hasPerm && $requireAll) {
                    return false;
                }
            }
            // If we've made it this far and $requireAll is FALSE, then NONE of the perms were found
            // If we've made it this far and $requireAll is TRUE, then ALL of the perms were found.
            // Return the value of $requireAll;
            return $requireAll;
        } else {
            if ($this->hasPermission($permission, false)) {
                return true;
            } else {
                if ($this->canInRoles($permission, false)) {
                    return true;
                }
            }
        }
        return false;
    }