Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Handle model instance in Authorize middleware #17898

Merged
merged 1 commit into from
Feb 12, 2017

Commits on Feb 12, 2017

  1. Handle model instance in Authorize middleware.

    This will help extending Middleware capabilities by giving it directly the Model to check.
    
    Implementation example :
    
    ```php
    <?php
    
    namespace App\Http\Middleware;
    
    use Closure;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Auth\Middleware\Authorize;
    
    class AuthorizeCommand extends Authorize
    {
        /**
         * Handle an incoming request.
         *
         * @param  \Illuminate\Http\Request  $request
         * @param  \Closure  $next
         * @return mixed
         */
        public function handle($request, Closure $next, $ability = null, ...$models)
        {
            if ((null !== $command = $request->route('command')) &&
                $command instanceof Model
            ) {
                return parent::handle($request, $next, 'access', $command);
            }
    
            return $next($request);
        }
    }
    ```
    shulard committed Feb 12, 2017
    Configuration menu
    Copy the full SHA
    89b296b View commit details
    Browse the repository at this point in the history