Is this intentional? It seems that Middleware should be able to change the request going in and out of it. It can pass along changes to other Middleware but after all the Middleware is run, Laravel ignores the changes on the initial request.
This Middleware runs on every request:
class GetLocale implements Middleware {
public function handle($request, Closure $next)
{
//url: site.com/en/someurl/
$modifiedRequest = $request->duplicate();
$language = $request->segment(1);
if(is_valid_language($language))
{
//do stuff with $language
$modifiedRequest->server->set('REQUEST_URI', strip_language($request->path());
//url: site.com/someurl/
return $next($modifiedRequest);
}
}
}
After GetLocale runs, the other Middleware functions as I would expect but \Illuminate\Routing\Stack::then() returns the original request because of getInitialSlice and a route not found exception is thrown because site.com/en/someurl/ doesn't actually exist.
Editing Illuminate\Routing\Stack to use a passed $request rather than $this->request everything function as expected and site.com/en/someurl/ resolves transparently to site.com/someurl/ .
The following works exactly as I'd expect.
protected function getInitialSlice(Closure $app)
{
return function($request) use ($app)
{
return call_user_func($app, $request);
};
}
On Middleware run later and not on every load, it always uses the passed $request at the end:
|
return (new Stack($this->container)) |
Is this intentional? It seems that Middleware should be able to change the request going in and out of it. It can pass along changes to other Middleware but after all the Middleware is run, Laravel ignores the changes on the initial request.
This Middleware runs on every request:
After GetLocale runs, the other Middleware functions as I would expect but
\Illuminate\Routing\Stack::then()returns the original request because of getInitialSlice and a route not found exception is thrown becausesite.com/en/someurl/doesn't actually exist.Editing Illuminate\Routing\Stack to use a passed $request rather than $this->request everything function as expected and
site.com/en/someurl/resolves transparently tosite.com/someurl/.The following works exactly as I'd expect.
On Middleware run later and not on every load, it always uses the passed $request at the end:
framework/src/Illuminate/Routing/ControllerDispatcher.php
Line 104 in 62ae860