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] pushMiddlewareToGroup not working on Provider::register method #36604

Closed
lk77 opened this issue Mar 15, 2021 · 3 comments
Closed

[8.x] pushMiddlewareToGroup not working on Provider::register method #36604

lk77 opened this issue Mar 15, 2021 · 3 comments

Comments

@lk77
Copy link

lk77 commented Mar 15, 2021

  • Laravel Version: 8.32.1
  • PHP Version: 7.2.27
  • Database Driver & Version: mysql 5.7

Description:

It seems that pushMiddlewareToGroup is not working when inside a provider register method

Steps To Reproduce:

Add a middleware inside register method, it does not work :

Route::pushMiddlewareToGroup('web', MyMiddleware::class);

middleware is not called at all.

add the same code in boot() method and see that it works

it was working fine on v8.25.0

My Use Case

i'm using https://github.com/NoelDeMartin/laravel-dusk-mocking to mock some facades inside my dusk tests, like Socialite,
and since their middleware is added in their provider, it cease to work at some point.

if i edit this file :
https://github.com/NoelDeMartin/laravel-dusk-mocking/blob/master/src/MockingServiceProvider.php

and move pushMiddlewareToGroup calls to the boot method, it works again.

thanks.

@driesvints
Copy link
Member

It's not meant that you execute services like this in a service provider's register method. The register methods are only there to wire things into Laravel's container. The boot method is the correct place for this.

@lk77
Copy link
Author

lk77 commented Mar 15, 2021

yes but it was working fine previously and a lot of third party packages were relying on it

@driesvints
Copy link
Member

@lk77 that wasn't intended to work. Sorry if this broke anything but we don't consider that a BC.

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