diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index dd370e36552f..95e3cd32d0bd 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -306,6 +306,7 @@ protected function parseControllerCallback() */ public function flushController() { + $this->computedMiddleware = null; $this->controller = null; } diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index 37c65c477766..37799448bf28 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -1772,14 +1772,17 @@ public function testRouteFlushController() $request = Request::create('count', 'GET'); $response = $router->dispatch($request); - $this->assertSame(1, (int) $response->getContent()); + $this->assertSame(1, $response->original['invokedCount']); + $this->assertSame(1, $response->original['middlewareInvokedCount']); $response = $router->dispatch($request); - $this->assertSame(2, (int) $response->getContent()); + $this->assertSame(2, $response->original['invokedCount']); + $this->assertSame(2, $response->original['middlewareInvokedCount']); $request->route()->flushController(); $response = $router->dispatch($request); - $this->assertSame(1, (int) $response->getContent()); + $this->assertSame(1, $response->original['invokedCount']); + $this->assertSame(1, $response->original['middlewareInvokedCount']); } public function testJsonResponseIsReturned() @@ -2323,15 +2326,29 @@ public function __invoke() } } -class ActionCountStub +class ActionCountStub extends Controller { - protected $count = 0; + protected $middlewareInvokedCount = 0; + + protected $invokedCount = 0; + + public function __construct() + { + $this->middleware(function ($request, $next) { + $this->middlewareInvokedCount++; + + return $next($request); + }); + } public function __invoke() { - $this->count++; + $this->invokedCount++; - return $this->count; + return [ + 'invokedCount' => $this->invokedCount, + 'middlewareInvokedCount' => $this->middlewareInvokedCount, + ]; } }