Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite laravel fortify controllers

I need to overwrite the login,register,logout and 2FA methods to add some logic, How can i publish it from the vendor?, is there something like php artisan vendor:publish .....

like image 390
sos5020 Avatar asked Nov 16 '25 14:11

sos5020


2 Answers

I find that i can overwrite any of fortify pipeline in FortifyServiceProvider by adding the flowing inside boot() function:

# overwrite example
$this->app->singleton(LoginResponseContract::class, LoginResponse::class);
$this->app->singleton(RegisterResponseContract::class, RegisterResponse::class);
.
.
.
like image 112
sos5020 Avatar answered Nov 18 '25 03:11

sos5020


It can be a good solution to use a new controller by rewriting the desired route Because then you will have more control power

Route::post('/register', [MyNewController::class, 'store'])
    ->middleware(['guest:'.config('fortify.guard')]);
like image 20
Sh4msi Avatar answered Nov 18 '25 04:11

Sh4msi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!