How to Override Laravel Fortify Default Registration Redirect
In this lesson, we will see how to override Laravel Fortify default registration redirect, sometimes when working with Laravel Fortify you want to redirect the user after he successfully creates an account to a specific route rather than the default one provided by Fortify.
Override Laravel Fortify default registration 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\RegisterResponse;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
$this->app->instance(RegisterResponse::class, new class implements RegisterResponse {
public function toResponse($request)
{
return redirect('/');
}
});
}
...