<?php

use GeneaLabs\LaravelCaffeine\Http\Controllers\LaravelCaffeineController;

if (hasWebMiddleware()) {
    Route::group(['middleware' => ['web']], function () {
        Route::get('genealabs/laravel-caffeine/drip', LaravelCaffeineController::class . '@drip');
    });
} else {
    Route::get('genealabs/laravel-caffeine/drip', LaravelCaffeineController::class . '@drip');
}

function hasWebMiddleware()
{
    $routes = Route::getRoutes()->getRoutes();

    foreach ($routes as $route) {
        $actions = (array) $route->getAction();

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

    return false;
}

<?php

use GeneaLabs\LaravelCaffeine\Helper;
use GeneaLabs\LaravelCaffeine\Http\Controllers\LaravelCaffeineController;

if ((new Helper())->routeHasMiddlewareGroup('web')) {
    Route::group(['middleware' => ['web']], function () {
        Route::get('genealabs/laravel-caffeine/drip', LaravelCaffeineController::class . '@drip');
    });
} else {
    Route::get('genealabs/laravel-caffeine/drip', LaravelCaffeineController::class . '@drip');
}

Use helper class to determine if middleware group exists
Use helper class to determine if middleware group exists
