Skip to content

Commit

Permalink
fix an issue with fluent uses (#13076)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored and taylorotwell committed Apr 8, 2016
1 parent 9937493 commit 8535763
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
@@ -824,7 +824,20 @@ public function name($name)
*/
public function uses($action)
{
return $this->setAction(array_merge($this->action, $this->parseAction($action)));
if (is_string($action)) {
$groupStack = last($this->router->getGroupStack());

if (isset($groupStack['namespace']) && strpos($action, '\\') !== 0) {
$action = $groupStack['namespace'].'\\'.$action;
}
}

$action = $this->parseAction([
'uses' => $action,
'controller' => $action,
]);

return $this->setAction(array_merge($this->action, $action));
}

/**
14 changes: 14 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
@@ -122,6 +122,20 @@ public function testFluentRouting()
$router->dispatch(Request::create('foo/bar', 'GET'));
}

public function testFluentRoutingWithControllerAction()
{
$router = $this->getRouter();
$router->get('foo/bar')->uses('RouteTestControllerStub@index');
$this->assertEquals('Hello World', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent());

$router = $this->getRouter();
$router->group(['namespace' => 'App'], function ($router) {
$router->get('foo/bar')->uses('RouteTestControllerStub@index');
});
$action = $router->getRoutes()->getRoutes()[0]->getAction();
$this->assertEquals('App\\RouteTestControllerStub@index', $action['controller']);
}

public function testMiddlewareGroups()
{
unset($_SERVER['__middleware.group']);

0 comments on commit 8535763

Please sign in to comment.