Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Fix router inconsistency for namespaced route groups #34793

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Illuminate/Routing/RouteRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
19 changes: 19 additions & 0 deletions tests/Routing/RouteRegistrarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down