Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
fix(Laravel):  Fixed get current route is null, reading gather middle…
Browse files Browse the repository at this point in the history
…ware error.
  • Loading branch information
medz committed Apr 8, 2018
1 parent d0ab007 commit 26c2841
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Laravel/Middleware/Cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 26c2841

Please sign in to comment.