private function middlewareGroupExists(string $group) : bool
{
$routes = collect(app('router')->getRoutes()->getRoutes());
return $routes->reduce(function ($carry, $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;
}