public function userCan($ability, $arguments = [])
    {
        $user = auth()->user();

        // If no arguments are specified, set it to the controller's model (default)
        if (empty($arguments)) {
            $arguments = static::$model;
        }

        // Get policy for model
        if (is_array($arguments)) {
            $model = reset($arguments);
        } else {
            $model = $arguments;
        }

        $modelPolicy = Gate::getPolicyFor($model);

        // If no policy exists for this model, then there's nothing to check
        if (is_null($modelPolicy)) {
            return true;
        }

        // Check if the authenticated user has the required ability for the model
        if ($user->can($ability, $arguments)) {
            return true;
        }

        return false;
    }
public function userCan($ability, $arguments = [])
    {
        $user = auth()->user();

        // If no arguments are specified, set it to the controller's model (default)
        if (empty($arguments)) {
            $arguments = static::$model;
        }

        // Get policy for model
        if (is_array($arguments)) {
            $model = reset($arguments);
        } else {
            $model = $arguments;
        }

        $modelPolicy = Gate::getPolicyFor($model);

        // If no policy exists for this model, then there's nothing to check
        if (is_null($modelPolicy)) {
            return true;
        }

        // Check if the authenticated user has the required ability for the model
        if ($user->can($ability, $arguments)) {
            return true;
        }

        return false;
    }
public function userCan ( $ ability , $ arguments = [ ] ) { $ user = auth ( ) -> user ( ) ; // If no arguments are specified, set it to the controller's model (default) if ( empty ( $ arguments ) ) { $ arguments = static :: $ model ; } // Get policy for model if ( is_array ( $ arguments ) ) { $ model = reset ( $ arguments ) ; } else { $ model = $ arguments ; } $ modelPolicy = Gate :: getPolicyFor ( $ model ) ; // If no policy exists for this model, then there's nothing to check if ( is_null ( $ modelPolicy ) ) { return true ; } // Check if the authenticated user has the required ability for the model if ( $ user -> can ( $ ability , $ arguments ) ) { return true ; } return false ; }
Determine if the currently logged in user can perform the specified ability on the model of the controller
When relevant, a specific instance of a model is used - otherwise, the model name.

Only checks if a policy exists for that model.

@param  string  $ability
@param  array|mixed  $arguments
@return bool
Determine if the currently logged in user can perform the specified ability on the model of the controller When relevant a specific instance of a model is used - otherwise the model name .