diff --git a/src/Illuminate/Routing/RouteRegistrar.php b/src/Illuminate/Routing/RouteRegistrar.php index 315314df0a48..679b10c28080 100644 --- a/src/Illuminate/Routing/RouteRegistrar.php +++ b/src/Illuminate/Routing/RouteRegistrar.php @@ -183,6 +183,10 @@ protected function compileAction($action) if (is_array($action) && is_callable($action) && ! Arr::isAssoc($action)) { + if (strncmp($action[0], '\\', 1)) { + $action[0] = '\\'.$action[0]; + } + $action = [ 'uses' => $action[0].'@'.$action[1], 'controller' => $action[0].'@'.$action[1], diff --git a/tests/Routing/RouteRegistrarTest.php b/tests/Routing/RouteRegistrarTest.php index a6bc297aa40d..2f97be3e03e5 100644 --- a/tests/Routing/RouteRegistrarTest.php +++ b/tests/Routing/RouteRegistrarTest.php @@ -149,6 +149,25 @@ public function testCanRegisterRouteWithControllerActionArray() $this->seeMiddleware('controller-middleware'); } + public function testCanRegisterNamespacedGroupRouteWithControllerActionArray() + { + $this->router->group(['namespace' => 'WhatEver'], function () { + $this->router->middleware('controller-middleware') + ->get('users', [RouteRegistrarControllerStub::class, 'index']); + }); + + $this->seeResponse('controller', Request::create('users', 'GET')); + $this->seeMiddleware('controller-middleware'); + + $this->router->group(['namespace' => 'WhatEver'], function () { + $this->router->middleware('controller-middleware') + ->get('users', ['\\'.RouteRegistrarControllerStub::class, 'index']); + }); + + $this->seeResponse('controller', Request::create('users', 'GET')); + $this->seeMiddleware('controller-middleware'); + } + public function testCanRegisterRouteWithArrayAndControllerAction() { $this->router->middleware('controller-middleware')->put('users', [