diff --git a/src/Laravel/Middleware/Cors.php b/src/Laravel/Middleware/Cors.php index 45b91aa..ad48fd2 100644 --- a/src/Laravel/Middleware/Cors.php +++ b/src/Laravel/Middleware/Cors.php @@ -95,9 +95,13 @@ protected function hasShouldRouteGroup($request): bool $shouldClsssName = ShouldGroup::class; $shouldAlias = collect(Route::getMiddleware())->flip()->get($shouldClsssName, $shouldClsssName); - $gatherMiddleware = collect(Route::getRoutes()->get())->first(function ($route) use ($request) { + $route = collect(Route::getRoutes()->get())->first(function ($route) use ($request) { return $route->matches($request, false); - })->gatherMiddleware(); + }); + if (! $route) { + return false; + } + $gatherMiddleware = $route->gatherMiddleware(); if (in_array($shouldClsssName, $gatherMiddleware) || in_array($shouldAlias, $gatherMiddleware)) { return true;