Skip to content

Commit

Permalink
[5.3] Resource routes url translations
Browse files Browse the repository at this point in the history
  • Loading branch information
shadoWalker89 committed Nov 16, 2016
1 parent c7b5683 commit 091f647
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/Illuminate/Routing/ResourceRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class ResourceRegistrar
*/
protected static $singularParameters = true;

/**
* Uri translations.
*
* @var array
*/
protected static $uriTranslations = [
'create' => 'create',
'edit' => 'edit'
];

/**
* Create a new resource registrar instance.
*
Expand Down Expand Up @@ -290,7 +300,7 @@ protected function addResourceIndex($name, $base, $controller, $options)
*/
protected function addResourceCreate($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name).'/create';
$uri = $this->getResourceUri($name).'/'.static::$uriTranslations['create'];

$action = $this->getResourceAction($name, $controller, 'create', $options);

Expand Down Expand Up @@ -344,7 +354,7 @@ protected function addResourceShow($name, $base, $controller, $options)
*/
protected function addResourceEdit($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name).'/{'.$base.'}/edit';
$uri = $this->getResourceUri($name).'/{'.$base.'}/'.static::$uriTranslations['edit'];

$action = $this->getResourceAction($name, $controller, 'edit', $options);

Expand Down Expand Up @@ -418,4 +428,25 @@ public static function setParameters(array $parameters = [])
{
static::$parameterMap = $parameters;
}

/**
* Get the uri translations.
*
* @return array
*/
public static function getUriTranslations()
{
return static::$uriTranslations;
}

/**
* Set the uri translations
*
* @param array $translations
* @return void
*/
public static function setUriTranslations(array $translations = [])
{
static::$uriTranslations = array_merge(static::$uriTranslations, $translations);
}
}
11 changes: 11 additions & 0 deletions src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ public function resourceParameters(array $parameters = [])
ResourceRegistrar::setParameters($parameters);
}

/**
* Set the uri translations.
*
* @param array $translations
* @return void
*/
public function uriTranslations(array $translations = [])
{
ResourceRegistrar::setUriTranslations($translations);
}

/**
* Register an array of resource controllers.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,17 @@ public function testResourceRouting()

$this->assertEquals('foo-bars/{foo_bar}', $routes[0]->getUri());
$this->assertEquals('prefix.foo-bars.show', $routes[0]->getName());

ResourceRegistrar::setUriTranslations([
'create' => 'ajouter',
'edit' => 'modifier'
]);
$router = $this->getRouter();
$router->resource('foo', 'FooController');
$routes = $router->getRoutes();

$this->assertEquals('foo/ajouter', $routes->getByName('foo.create')->getUri());
$this->assertEquals('foo/{foo}/modifier', $routes->getByName('foo.edit')->getUri());
}

public function testResourceRoutingParameters()
Expand Down

0 comments on commit 091f647

Please sign in to comment.