In L4, we used to be able to load service providers based on the environment using append_config.
The recommended way now in L5 is to instead load it conditionally in AppServiceProvidor:
if ($this->app->environment('local'))
{
$this->app->register('LocalOnlyServiceProvider');
}
The same can't be said for middleware. There seems to currently be no way to do the same for middleware. The only way I was able to accomplish conditional middleware loading was by extending the app kernel's constructor and load it there. Ugh :cry:
Another possible solution might be to create my own ConditionalMiddleware that always runs, and then pass the request through to various additional middleare conditionally. Again, ugh!
For reference: slack discussion
I think there should be a built-in way to do this, but I'm not sure the exact approach to take.
Ideas?
Perhaps add the middleware option back to App, like before? That was also proposed to simplify middleware in packages..
$this->app->middleware('MyConditionalMiddleware');
Doesn't the order of middlewares matter? If so, the approach with addConditionalMiddleware() method seems bad.
This partially duplicates https://github.com/laravel/framework/issues/6211.
Closing this.
Taylor says to just do it in the kernel's handle method, like this.
Most helpful comment
Closing this.
Taylor says to just do it in the kernel's
handlemethod, like this.