How to Override Laravel Fortify Default Login Redirect
In this lesson, we will see how to override Laravel Fortify default login redirect, sometimes when working with Laravel Fortify you want to redirect the user after he successfully logs in to a specific route rather than the default one provided by Fortify.
Override Laravel Fortify default login redirect
Let's assume that we want to redirect the user to the home page to do that inside the FortifyServiceProvider register function add the code below:
<?php
namespace App\Providers;
...
use Laravel\Fortify\Contracts\LoginResponse;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
$this->app->instance(LoginResponse::class, new class implements LoginResponse {
public function toResponse($request)
{
return redirect('/');
}
});
}
...