Skip to content

Commit

Permalink
Updated detection of middleware groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Jul 1, 2019
1 parent 4a24520 commit 7d97fba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Change Log

## [0.8.2] - 2019-06-30
### Changed
- method of checking registered middleware groups to use `hasMiddlewareGroup()`.

## [0.6.12] - 5 Aug 2018
### Fixed
- middleware response to be a view instead of string. Thanks @dallincoons, #96 #95.
Expand Down
20 changes: 1 addition & 19 deletions src/Providers/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Service extends ServiceProvider
{
public function boot()
{
app('router')->group($this->middlewareGroupExists('web')
app('router')->group(app("router")->hasMiddlewareGroup('web')
? ['middleware' => 'web']
: [], function () {
require __DIR__ . '/../../routes/web.php';
Expand Down Expand Up @@ -53,24 +53,6 @@ public function boot()
}
}

protected function middlewareGroupExists(string $group) : bool
{
$routes = collect(app('router')->getRoutes()->getRoutes());

return $routes->reduce(function ($carry, Route $route) use ($group) {
$carry = ($carry ?? false) ?: false;
$actions = (array) $route->getAction();

if (array_key_exists('middleware', $actions)
&& in_array($group, (array) $actions['middleware'])
) {
return true;
}

return $carry;
}) ?? false;
}

protected function shouldRegisterGlobalMiddleware() : bool
{
return (! request()->ajax()
Expand Down

0 comments on commit 7d97fba

Please sign in to comment.