diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index 05aa9a383890..dd370e36552f 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -299,6 +299,16 @@ protected function parseControllerCallback() return Str::parseCallback($this->action['uses']); } + /** + * Flush the cached container instance on the route. + * + * @return void + */ + public function flushController() + { + $this->controller = null; + } + /** * Determine if the route matches a given request. * diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index 14215cbea62c..37c65c477766 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -1763,6 +1763,25 @@ public function testResponseIsReturned() $this->assertNotInstanceOf(JsonResponse::class, $response); } + public function testRouteFlushController() + { + $container = new Container; + $router = $this->getRouter(); + + $router->get('count', ActionCountStub::class); + $request = Request::create('count', 'GET'); + + $response = $router->dispatch($request); + $this->assertSame(1, (int) $response->getContent()); + + $response = $router->dispatch($request); + $this->assertSame(2, (int) $response->getContent()); + + $request->route()->flushController(); + $response = $router->dispatch($request); + $this->assertSame(1, (int) $response->getContent()); + } + public function testJsonResponseIsReturned() { $router = $this->getRouter(); @@ -2304,6 +2323,18 @@ public function __invoke() } } +class ActionCountStub +{ + protected $count = 0; + + public function __invoke() + { + $this->count++; + + return $this->count; + } +} + interface ExampleMiddlewareContract { //