From 104c539c342d395e2f3c4ba7339df095f83f6352 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 23 Jan 2020 08:48:37 -0600 Subject: [PATCH] formatting --- .../Routing/PendingResourceRegistration.php | 4 +- src/Illuminate/Routing/ResourceRegistrar.php | 38 +++++++++---------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/Illuminate/Routing/PendingResourceRegistration.php b/src/Illuminate/Routing/PendingResourceRegistration.php index 79ce47317968..b7d158ddd7b2 100644 --- a/src/Illuminate/Routing/PendingResourceRegistration.php +++ b/src/Illuminate/Routing/PendingResourceRegistration.php @@ -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 @@ -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 diff --git a/src/Illuminate/Routing/ResourceRegistrar.php b/src/Illuminate/Routing/ResourceRegistrar.php index 498aa5ee7370..f9353da035e7 100644 --- a/src/Illuminate/Routing/ResourceRegistrar.php +++ b/src/Illuminate/Routing/ResourceRegistrar.php @@ -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.'}'; @@ -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']; @@ -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.'}'; @@ -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.'}'; @@ -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. * @@ -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. *