diff --git a/src/Illuminate/Routing/RouteAction.php b/src/Illuminate/Routing/RouteAction.php index 678806ba5456..92d9748671ef 100644 --- a/src/Illuminate/Routing/RouteAction.php +++ b/src/Illuminate/Routing/RouteAction.php @@ -29,6 +29,11 @@ public static function parse($uri, $action) // as the "uses" property, because there is nothing else we need to do when // it is available. Otherwise we will need to find it in the action list. if (is_callable($action)) { + if (\is_array($action)) { + [$class, $method] = $action; + $action = $class.'@'.$method; + } + return ['uses' => $action]; } diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index 7167089ee5d0..635977d93222 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -1289,6 +1289,26 @@ public function testControllerRouting() $this->assertFalse(isset($_SERVER['route.test.controller.except.middleware'])); } + public function testControllerRoutingArrayCallable() + { + unset( + $_SERVER['route.test.controller.middleware'], $_SERVER['route.test.controller.except.middleware'], + $_SERVER['route.test.controller.middleware.class'], + $_SERVER['route.test.controller.middleware.parameters.one'], $_SERVER['route.test.controller.middleware.parameters.two'] + ); + + $router = $this->getRouter(); + + $router->get('foo/bar', [RouteTestControllerStub::class, 'index']); + + $this->assertEquals('Hello World', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent()); + $this->assertTrue($_SERVER['route.test.controller.middleware']); + $this->assertEquals(\Illuminate\Http\Response::class, $_SERVER['route.test.controller.middleware.class']); + $this->assertEquals(0, $_SERVER['route.test.controller.middleware.parameters.one']); + $this->assertEquals(['foo', 'bar'], $_SERVER['route.test.controller.middleware.parameters.two']); + $this->assertFalse(isset($_SERVER['route.test.controller.except.middleware'])); + } + public function testCallableControllerRouting() { $router = $this->getRouter();