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

Authorize middleware doen't recognize my model if it's a valid Model instance #17848

Closed
shulard opened this issue Feb 9, 2017 · 1 comment
Closed

Comments

@shulard
Copy link
Contributor

shulard commented Feb 9, 2017

  • Laravel Version: 5.2, 5.3, 5.4
  • PHP Version: all

Description:

Inside one of my projects, I've found the if I gave a valid Model instance to the Authorize middleware, the Model is not recognized as one and the $request->route($model); code is called.
This call will fail because my $model variable is an object and the route method need a string as parameter name.

I think that it'll be better if the getGateArguments method in Authorize middleware verify if the given model is not already a Model instance...

I can make a PR but as it concerned 3 different branches what's the right way to do ? Create a PR for each version ?

Steps To Reproduce:

I created an extension of the Authorize middleware like this which failed recognizing the model :

<?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);
    }
}
@themsaid
Copy link
Member

themsaid commented Feb 9, 2017

You can open a PR on 5.4 since it's not a breaking change. 5.3 and prior are closed for new features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants