@babai9 I think I have a solution for Laravel 11.
Please note that this solution is not necessary for the livewire starter kits as the logout is handled by Livewire.
Create a new middleware class that extends the framework VerifyCsrfToken middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
use Illuminate\Support\Facades\Auth;
class CheckCsrf extends ValidateCsrfToken
{
protected $except = [
// other routes that need excepting
'stripe/*',
];
public function handle($request, Closure $next): Response
{
if($request->route()->named('logout')) {
if (!Auth::check() || Auth::guard()->viaRemember()) {
$this->except[] = 'logout';
}
}
return parent::handle($request, $next);
}
}
then in bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
$middleware->web(replace: [
Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class =>
App\Http\Middleware\CheckCsrf::class]);
})
This tells the app to swap out the framework csrf validation for ours so that we can add the logic needed to the handle function.