|
14 | 14 | use Illuminate\Container\Container; |
15 | 15 | use Dingo\Api\Contract\Routing\Adapter; |
16 | 16 | use Dingo\Api\Contract\Debug\ExceptionHandler; |
| 17 | +use Illuminate\Routing\Route as IlluminateRoute; |
17 | 18 | use Illuminate\Http\Response as IlluminateResponse; |
| 19 | +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
18 | 20 | use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; |
19 | 21 |
|
20 | 22 | class Router |
@@ -622,6 +624,17 @@ public function getCurrentRoute() |
622 | 624 | return; |
623 | 625 | } |
624 | 626 |
|
| 627 | + // We need to recompile the route, adding the where clause (for pattern restrictions) and check again |
| 628 | + if (is_object($route) && $route instanceof IlluminateRoute) { |
| 629 | + $route->compiled = false; |
| 630 | + $this->addWhereClausesToRoute($route); |
| 631 | + |
| 632 | + // If the matching fails, it would be due to a parameter format validation check fail |
| 633 | + if (! $route->matches($this->container['request'])) { |
| 634 | + throw new NotFoundHttpException('Not Found!'); |
| 635 | + } |
| 636 | + } |
| 637 | + |
625 | 638 | return $this->currentRoute = $this->createRoute($route); |
626 | 639 | } |
627 | 640 |
|
@@ -844,4 +857,22 @@ public function currentRouteUses($action) |
844 | 857 | { |
845 | 858 | return $this->currentRouteAction() == $action; |
846 | 859 | } |
| 860 | + |
| 861 | + /** |
| 862 | + * Add the necessary where clauses to the route based on its initial registration. |
| 863 | + * |
| 864 | + * @param \Illuminate\Routing\Route $route |
| 865 | + * |
| 866 | + * @return \Illuminate\Routing\Route |
| 867 | + */ |
| 868 | + protected function addWhereClausesToRoute($route) |
| 869 | + { |
| 870 | + $patterns = app()->make(\Illuminate\Routing\Router::class)->getPatterns(); |
| 871 | + |
| 872 | + $route->where(array_merge( |
| 873 | + $patterns, $route->getAction()['where'] ?? [] |
| 874 | + )); |
| 875 | + |
| 876 | + return $route; |
| 877 | + } |
847 | 878 | } |
0 commit comments