Spatie\Authorize\Middleware\Authorize::hasRequiredAbility PHP Method

hasRequiredAbility() protected method

Determine if the currently logged in use has the given ability.
protected hasRequiredAbility ( $user, string | null $ability = null, Model | null $model = null ) : boolean
$user
$ability string | null
$model Illuminate\Database\Eloquent\Model | null
return boolean
    protected function hasRequiredAbility($user, $ability = null, $model = null)
    {
        if (!$user) {
            return false;
        }
        if (is_null($ability)) {
            return true;
        }
        /*
         * Some gates may check on number of arguments given. If model
         * is null, don't pass it as an argument.
         */
        if (is_null($model)) {
            return $user->can($ability);
        }
        return $user->can($ability, $model);
    }