diff --git a/src/Illuminate/Routing/RoutingServiceProvider.php b/src/Illuminate/Routing/RoutingServiceProvider.php index 8eea5ca5ecea..2a3d52266888 100755 --- a/src/Illuminate/Routing/RoutingServiceProvider.php +++ b/src/Illuminate/Routing/RoutingServiceProvider.php @@ -66,7 +66,7 @@ protected function registerUrlGenerator() // get the information it needs to function. This just provides some of // the convenience features to this URL generator like "signed" URLs. $url->setSessionResolver(function () { - return $this->app['session']; + return $this->app['session'] ?? null; }); $url->setKeyResolver(function () { diff --git a/tests/Integration/Routing/PreviousUrlTest.php b/tests/Integration/Routing/PreviousUrlTest.php new file mode 100644 index 000000000000..70491e8a6d1c --- /dev/null +++ b/tests/Integration/Routing/PreviousUrlTest.php @@ -0,0 +1,44 @@ +postJson('/previous-url'); + + $this->assertEquals(422, $response->status()); + } + + protected function getApplicationProviders($app) + { + $providers = parent::getApplicationProviders($app); + + return array_filter($providers, function ($provider) { + return $provider !== SessionServiceProvider::class; + }); + } +} + +class DummyFormRequest extends FormRequest +{ + public function rules() + { + return [ + 'foo' => [ + 'required', + 'string', + ], + ]; + } +}