diff --git a/src/Http/RouteCollection.php b/src/Http/RouteCollection.php index 3400e0f46..500ac8d58 100644 --- a/src/Http/RouteCollection.php +++ b/src/Http/RouteCollection.php @@ -80,16 +80,19 @@ class RouteCollection return $this->dataGenerator->getData(); } - public function getPath($name, $parameters = []) + protected function fixPathPart(&$part, $key, array $parameters) + { + if (is_array($part) && array_key_exists($part[0], $parameters)) { + $part = $parameters[$part[0]]; + } + } + + public function getPath($name, array $parameters = []) { $parts = $this->reverse[$name][0]; - $path = implode('', array_map(function ($part) use ($parameters) { - if (is_array($part)) { - $part = $parameters[$part[0]]; - } - return $part; - }, $parts)); + array_walk($parts, [$this, 'fixPathPart'], $parameters); + $path = implode('', $parts); $path = '/' . ltrim($path, '/'); return $path;