How to Override Laravel Fortify Default Login Redirect
Updated 2 weeks ago
admin
PHP
/
Laravel
In this lesson, we will see how to override Laravel Fortify's default login redirect. Sometimes, when working with Laravel Fortify, you want to redirect the user after he successfully log 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('/');
}
});
}
...