diff --git a/src/TurboServiceProvider.php b/src/TurboServiceProvider.php index 81a43bd9..0b393300 100644 --- a/src/TurboServiceProvider.php +++ b/src/TurboServiceProvider.php @@ -2,12 +2,12 @@ namespace Tonysm\TurboLaravel; +use Illuminate\Contracts\Http\Kernel; use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Response as ResponseFacade; -use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; use Illuminate\Testing\TestResponse; @@ -36,10 +36,7 @@ public function boot() $this->configureMacros(); $this->configureRequestAndResponseMacros(); $this->configureTestResponseMacros(); - - if (config('turbo-laravel.automatically_register_middleware', true)) { - Route::prependMiddlewareToGroup('web', TurboMiddleware::class); - } + $this->configureMiddleware(); } public function register() @@ -158,4 +155,15 @@ private function configureTestResponseMacros() ); }); } + + protected function configureMiddleware(): void + { + if (! config('turbo-laravel.automatically_register_middleware', true)) { + return; + } + + /** @var Kernel $kernel */ + $kernel = resolve(Kernel::class); + $kernel->prependMiddlewareToGroup('web', TurboMiddleware::class); + } }