diff --git a/src/Routing/Adapter/Laravel.php b/src/Routing/Adapter/Laravel.php index e6faeae81..4688f8509 100644 --- a/src/Routing/Adapter/Laravel.php +++ b/src/Routing/Adapter/Laravel.php @@ -2,12 +2,12 @@ namespace Dingo\Api\Routing\Adapter; +use Dingo\Api\Contract\Routing\Adapter; +use Dingo\Api\Exception\UnknownVersionException; use Illuminate\Http\Request; use Illuminate\Routing\Route; -use Illuminate\Routing\Router; -use Dingo\Api\Contract\Routing\Adapter; use Illuminate\Routing\RouteCollection; -use Dingo\Api\Exception\UnknownVersionException; +use Illuminate\Routing\Router; class Laravel implements Adapter { @@ -147,6 +147,9 @@ public function addRoute(array $methods, array $versions, $uri, $action) { $this->createRouteCollections($versions); + // Add where-patterns from original laravel router + $action['where'] = array_merge($this->router->getPatterns(), $action['where'] ?? []); + $route = new Route($methods, $uri, $action); $route->where($action['where']); diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 1e39f98db..52c42f28f 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -3,20 +3,18 @@ namespace Dingo\Api\Routing; use Closure; -use Exception; -use RuntimeException; +use Dingo\Api\Contract\Debug\ExceptionHandler; +use Dingo\Api\Contract\Routing\Adapter; +use Dingo\Api\Http\InternalRequest; use Dingo\Api\Http\Request; -use Illuminate\Support\Arr; -use Illuminate\Support\Str; use Dingo\Api\Http\Response; -use Illuminate\Http\JsonResponse; -use Dingo\Api\Http\InternalRequest; +use Exception; use Illuminate\Container\Container; -use Dingo\Api\Contract\Routing\Adapter; -use Dingo\Api\Contract\Debug\ExceptionHandler; -use Illuminate\Routing\Route as IlluminateRoute; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Response as IlluminateResponse; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Illuminate\Support\Arr; +use Illuminate\Support\Str; +use RuntimeException; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; class Router @@ -624,17 +622,6 @@ public function getCurrentRoute() return; } - // We need to recompile the route, adding the where clause (for pattern restrictions) and check again - if (is_object($route) && $route instanceof IlluminateRoute) { - $route->compiled = false; - $this->addWhereClausesToRoute($route); - - // If the matching fails, it would be due to a parameter format validation check fail - if (! $route->matches($this->container['request'])) { - throw new NotFoundHttpException('Not Found!'); - } - } - return $this->currentRoute = $this->createRoute($route); } @@ -857,22 +844,4 @@ public function currentRouteUses($action) { return $this->currentRouteAction() == $action; } - - /** - * Add the necessary where clauses to the route based on its initial registration. - * - * @param \Illuminate\Routing\Route $route - * - * @return \Illuminate\Routing\Route - */ - protected function addWhereClausesToRoute($route) - { - $patterns = app()->make(\Illuminate\Routing\Router::class)->getPatterns(); - - $route->where(array_merge( - $patterns, $route->getAction()['where'] ?? [] - )); - - return $route; - } }