Skip to content

Commit 300bacc

Browse files
authored
Merge pull request #103 from hotwired-laravel/fix-auto-binding-middleware
Fix middleware not automatically registered
2 parents 08e953d + a0b83c1 commit 300bacc

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/TurboServiceProvider.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Tonysm\TurboLaravel;
44

5+
use Illuminate\Contracts\Http\Kernel;
56
use Illuminate\Contracts\Routing\ResponseFactory;
67
use Illuminate\Http\Request;
78
use Illuminate\Http\Response;
89
use Illuminate\Support\Facades\Blade;
910
use Illuminate\Support\Facades\Response as ResponseFacade;
10-
use Illuminate\Support\Facades\Route;
1111
use Illuminate\Support\ServiceProvider;
1212
use Illuminate\Support\Str;
1313
use Illuminate\Testing\TestResponse;
@@ -36,10 +36,7 @@ public function boot()
3636
$this->configureMacros();
3737
$this->configureRequestAndResponseMacros();
3838
$this->configureTestResponseMacros();
39-
40-
if (config('turbo-laravel.automatically_register_middleware', true)) {
41-
Route::prependMiddlewareToGroup('web', TurboMiddleware::class);
42-
}
39+
$this->configureMiddleware();
4340
}
4441

4542
public function register()
@@ -158,4 +155,15 @@ private function configureTestResponseMacros()
158155
);
159156
});
160157
}
158+
159+
protected function configureMiddleware(): void
160+
{
161+
if (! config('turbo-laravel.automatically_register_middleware', true)) {
162+
return;
163+
}
164+
165+
/** @var Kernel $kernel */
166+
$kernel = resolve(Kernel::class);
167+
$kernel->prependMiddlewareToGroup('web', TurboMiddleware::class);
168+
}
161169
}

0 commit comments

Comments
 (0)