getRoutes(); /** @var string[] $methods */ $methods = array_diff(Router::$verbs, [$request->getMethod(), 'OPTIONS']); foreach ($methods as $method) { // Get all routes for method without fallback routes /** @var Route[]|Collection $routes */ $routes = collect($routeCollection->get($method))->filter(static function ($route) { /** @var RouteModel $route */ return !$route->isFallback && $route->uri !== '{fallbackPlaceholder}'; }); // Look if any route have match with current request $mismatch = $routes->first(static function ($value) use ($request) { /** @var RouteModel $value */ return $value->matches($request, false); }); // Throw wrong-method exception if matches found if ($mismatch !== null) { throw new MethodNotAllowedHttpException([]); } } // No matches, throw not-found exception throw new NotFoundHttpException(); } }