Skip to content

Commit

Permalink
Merge pull request #16352 from shadoWalker89/resource_basename
Browse files Browse the repository at this point in the history
[5.3] A resource can define the route basename
  • Loading branch information
taylorotwell committed Nov 15, 2016
2 parents ef11bd7 + 2742119 commit 6c90b2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Illuminate/Routing/ResourceRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ protected function getResourceAction($resource, $controller, $method, $options)
*/
protected function getResourceName($resource, $method, $options)
{
if (isset($options['names'][$method])) {
return $options['names'][$method];
if (isset($options['names'])) {
if (is_string($options['names'])) {
$resource = $options['names'];
} elseif (isset($options['names'][$method])) {
return $options['names'][$method];
}
}

// If a global prefix has been assigned to all names for this resource, we will
Expand Down
11 changes: 11 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,17 @@ public function testResourceRouteNaming()

$this->assertTrue($router->getRoutes()->hasNamedRoute('foo'));
$this->assertTrue($router->getRoutes()->hasNamedRoute('bar'));

$router = $this->getRouter();
$router->resource('foo', 'FooController', ['names' => 'bar']);

$this->assertTrue($router->getRoutes()->hasNamedRoute('bar.index'));
$this->assertTrue($router->getRoutes()->hasNamedRoute('bar.show'));
$this->assertTrue($router->getRoutes()->hasNamedRoute('bar.create'));
$this->assertTrue($router->getRoutes()->hasNamedRoute('bar.store'));
$this->assertTrue($router->getRoutes()->hasNamedRoute('bar.edit'));
$this->assertTrue($router->getRoutes()->hasNamedRoute('bar.update'));
$this->assertTrue($router->getRoutes()->hasNamedRoute('bar.destroy'));
}

public function testRouterFiresRoutedEvent()
Expand Down

0 comments on commit 6c90b2d

Please sign in to comment.