Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 23, 2020
1 parent b54799c commit 104c539
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Routing/PendingResourceRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function parameter($previous, $new)
}

/**
* Set a middleware to the resource.
* Add middleware to the resource routes.
*
* @param mixed $middleware
* @return \Illuminate\Routing\PendingResourceRegistration
Expand All @@ -154,7 +154,7 @@ public function middleware($middleware)
}

/**
* Set the shallow option for a resource.
* Indicate that the resource routes should have "shallow" nesting.
*
* @param bool $shallow
* @return \Illuminate\Routing\PendingResourceRegistration
Expand Down
38 changes: 18 additions & 20 deletions src/Illuminate/Routing/ResourceRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function addResourceStore($name, $base, $controller, $options)
*/
protected function addResourceShow($name, $base, $controller, $options)
{
$name = $this->getNameWithShallowness($name, $options);
$name = $this->getShallowName($name, $options);

$uri = $this->getResourceUri($name).'/{'.$base.'}';

Expand All @@ -250,7 +250,7 @@ protected function addResourceShow($name, $base, $controller, $options)
*/
protected function addResourceEdit($name, $base, $controller, $options)
{
$name = $this->getNameWithShallowness($name, $options);
$name = $this->getShallowName($name, $options);

$uri = $this->getResourceUri($name).'/{'.$base.'}/'.static::$verbs['edit'];

Expand All @@ -270,7 +270,7 @@ protected function addResourceEdit($name, $base, $controller, $options)
*/
protected function addResourceUpdate($name, $base, $controller, $options)
{
$name = $this->getNameWithShallowness($name, $options);
$name = $this->getShallowName($name, $options);

$uri = $this->getResourceUri($name).'/{'.$base.'}';

Expand All @@ -290,7 +290,7 @@ protected function addResourceUpdate($name, $base, $controller, $options)
*/
protected function addResourceDestroy($name, $base, $controller, $options)
{
$name = $this->getNameWithShallowness($name, $options);
$name = $this->getShallowName($name, $options);

$uri = $this->getResourceUri($name).'/{'.$base.'}';

Expand All @@ -299,6 +299,20 @@ protected function addResourceDestroy($name, $base, $controller, $options)
return $this->router->delete($uri, $action);
}

/**
* Get the name for a given resource with shallowness applied when applicable.
*
* @param string $name
* @param array $options
* @return string
*/
protected function getShallowName($name, $options)
{
return isset($options['shallow']) && $options['shallow']
? last(explode('.', $name))
: $name;
}

/**
* Get the base resource URI for a given resource.
*
Expand Down Expand Up @@ -409,22 +423,6 @@ protected function getResourceRouteName($resource, $method, $options)
return trim(sprintf('%s%s.%s', $prefix, $name, $method), '.');
}

/**
* Get the name for a given resource with shallowness applied when needed.
*
* @param string $name
* @param array $options
* @return string
*/
protected function getNameWithShallowness($name, $options)
{
if (isset($options['shallow']) && $options['shallow']) {
return last(explode('.', $name));
} else {
return $name;
}
}

/**
* Set or unset the unmapped global parameters to singular.
*
Expand Down

0 comments on commit 104c539

Please sign in to comment.