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

[8.x] Computing controller middleware before getting excluding middleware #37259

Merged
merged 1 commit into from
May 4, 2021
Merged

Conversation

allowing
Copy link
Contributor

@allowing allowing commented May 4, 2021

To do so, you can call withoutMiddleware in the constructor

To do so, you can call `withoutMiddleware` in the constructor
@allowing
Copy link
Contributor Author

allowing commented May 4, 2021

Otherwise, calling withoutMiddleware in the controller will not work.

@allowing allowing changed the title Calculate controller middleware before excluding middleware. Computing controller middleware before getting excluding middleware. May 4, 2021
@taylorotwell
Copy link
Member

Interesting - why doesn't it work if the code is where we had it?

@allowing
Copy link
Contributor Author

allowing commented May 4, 2021

Because we get the exclusion middleware first, and then calculate the controller middleware. It is possible that withoutMiddleware will be called in the constructor. But the exclusion middleware has been acquired before this.

@allowing
Copy link
Contributor Author

allowing commented May 4, 2021

class Foo
{
    $this->middleware(Bar::class)->only('index');

    // many many code ....

    // This should be computed first
    \Route::getRoutes()->getByName('index')->withoutMiddleware(Bar::class);
}

@allowing
Copy link
Contributor Author

allowing commented May 4, 2021

微信截图_20210505000556
This is my actual case, I want to cancel the middleware in the controller, and found that the original logic is not working

@GrahamCampbell GrahamCampbell changed the title Computing controller middleware before getting excluding middleware. [8.x] Computing controller middleware before getting excluding middleware. May 4, 2021
@GrahamCampbell GrahamCampbell changed the title [8.x] Computing controller middleware before getting excluding middleware. [8.x] Computing controller middleware before getting excluding middleware May 4, 2021
@taylorotwell taylorotwell merged commit d986da0 into laravel:8.x May 4, 2021
@allowing allowing deleted the patch-5 branch May 5, 2021 01:49
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

Successfully merging this pull request may close these issues.

2 participants