From 26c2841b75e6fbcc3849579adee1b609392a4162 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Sun, 8 Apr 2018 16:47:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(Laravel):=20=C2=A0Fixed=20get=20current=20r?= =?UTF-8?q?oute=20is=20null,=20reading=20gather=20middleware=20error.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/Middleware/Cors.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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;