From 0283a7ecf8ade64fdc7d5a3454c3ff191c7f7473 Mon Sep 17 00:00:00 2001 From: imanghafoori Date: Sun, 11 Oct 2020 07:17:34 +0330 Subject: [PATCH 1/3] fix router for array actions within namespaced groups --- src/Illuminate/Routing/RouteRegistrar.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Illuminate/Routing/RouteRegistrar.php b/src/Illuminate/Routing/RouteRegistrar.php index 315314df0a48..fd7bef88f615 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)) { + // Start with a backslash, if it is not already starting with. + if (strncmp($action[0], '\\', 1)) { + $action[0] = '\\'.$action[0]; + } $action = [ 'uses' => $action[0].'@'.$action[1], 'controller' => $action[0].'@'.$action[1], From ca6fc995faaea84151d3eb3e55da584af00846a9 Mon Sep 17 00:00:00 2001 From: imanghafoori Date: Sun, 11 Oct 2020 09:05:32 +0330 Subject: [PATCH 2/3] add test for array action within namespaced groups --- tests/Routing/RouteRegistrarTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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', [ From 8c3818631ff35dbb5ca64c5dcd9d00085378db22 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 12 Oct 2020 09:16:09 -0500 Subject: [PATCH 3/3] Update RouteRegistrar.php --- src/Illuminate/Routing/RouteRegistrar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Routing/RouteRegistrar.php b/src/Illuminate/Routing/RouteRegistrar.php index fd7bef88f615..679b10c28080 100644 --- a/src/Illuminate/Routing/RouteRegistrar.php +++ b/src/Illuminate/Routing/RouteRegistrar.php @@ -183,10 +183,10 @@ protected function compileAction($action) if (is_array($action) && is_callable($action) && ! Arr::isAssoc($action)) { - // Start with a backslash, if it is not already starting with. if (strncmp($action[0], '\\', 1)) { $action[0] = '\\'.$action[0]; } + $action = [ 'uses' => $action[0].'@'.$action[1], 'controller' => $action[0].'@'.$action[1],