Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jerdav's avatar

Laravel Filament logout

the logout redirects to admin/login, I would like to modify this redirection to the home page of the site "/". how do we change this laravel 10 filament 2

0 likes
8 replies
LaryAI's avatar
Level 58

To change the redirection after logout in Laravel Filament, you can modify the logout method in the app/Http/Controllers/Filament/Auth/LogoutController.php file.

Here's an example of how you can modify the logout method to redirect to the home page of the site:

<?php

namespace App\Http\Controllers\Filament\Auth;

use Filament\Http\Controllers\Auth\LogoutController as BaseLogoutController;
use Illuminate\Http\Request;

class LogoutController extends BaseLogoutController
{
    public function logout(Request $request)
    {
        $this->guard()->logout();

        $request->session()->invalidate();

        $request->session()->regenerateToken();

        return redirect('/');
    }
}

In this example, we're simply returning a redirect response to the home page of the site using the redirect helper function.

Make sure to import the necessary classes at the top of the file.

Hope this helps!

jerdav's avatar

this is not the correct solution for filament version 2. There is no Filament/Auth, everything is in the vendor folder, I would need to override the vendor/filament/src/http/responses/auth/logoutResponse file. php but I don't know how?

michael-grunewalder's avatar

You could add a route in your web.php, somethign like:

Route::post('/auth/logout',[YourCustomLogoutClass::class,'yourLogoutFunction'])->name('filament.auth.logout')

and do your custom logic in there. That's what I do until there is a better solution.

lucvk's avatar
lucvk
Best Answer
Level 9

@michael-grunewalder Following is an elegant way to solve this:

  1. Create a class that implements Filament\Http\Responses\Auth\Contracts\LogoutResponse. In the toResponse method you can set the return path
  2. In your AppServiceProvider register this class as implementation for the filament LogoutResponse contract.

namespace App\Http\Responses;

use Filament\Http\Responses\Auth\Contracts\LogoutResponse as Responsable; use Illuminate\Http\RedirectResponse;

class LogoutResponse implements Responsable { public function toResponse($request): RedirectResponse { return redirect()->to( config('filament.path'), // config('filament.auth.pages.login') ? route('filament.auth.login') : config('filament.path'), ); } }

use Filament\Http\Responses\Auth\Contracts\LogoutResponse; class AppServiceProvider extends ServiceProvider { /** * Register any application services. */ public function register(): void { // $this->app->singleton(LogoutResponse::class, function(Application $app){ return new \App\Http\Responses\LogoutResponse(); }); }

3 likes
ajgraaff's avatar

@lucvk Unfortunately if you cache your routes this won't work as there will be duplicate routes with the same name. "Unable to prepare route [app/logout] for serialization. Another route has already been assigned name [filament.auth.logout]."

1 like
jerdav's avatar

Thank you for your help, this solution works perfectly

descarlos2013's avatar

Filament V3 with multipanel You can write:

namespace App\Http\Controllers\Filament;

use Filament\Facades\Filament;
use Filament\Http\Controllers\Auth\LogoutController as FilamentLogoutController;
use Illuminate\Http\Request;

class LogoutController extends FilamentLogoutController
{
    public function logout(Request $request)
    {
        Filament::auth()->logout();
        $request->session()->invalidate();
        $request->session()->regenerateToken();

        return redirect('/');
    }
}

And add in web.php route:

Maybe you can omit "admin" in route name if only has a base admin panel. No tested yet!

Route::post('/auth/logout', [LogoutController::class, 'logout'])->name('filament.admin.auth.logout');
3 likes

Please or to participate in this conversation.