Skip to content

Commit

Permalink
Merge pull request #103 from hotwired-laravel/fix-auto-binding-middle…
Browse files Browse the repository at this point in the history
…ware

Fix middleware not automatically registered
  • Loading branch information
tonysm authored Mar 7, 2023
2 parents 08e953d + a0b83c1 commit 300bacc
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/TurboServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 300bacc

Please sign in to comment.