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

YeZawHein's avatar

Laravel Fortify - override login request validation

I want to add google recaptcha in Laravel Fortify login validation rules.I didn't find at the documentation how to add or override this.I found Login validation in vendor\laravel\fortify\src\Http\Requests\LoginRequest.php but i know that is a bad idea to make changes in the vendor folder.How to do override the proper way?

0 likes
6 replies
devingray_'s avatar

You can add this in the boot method of your FortifyService Provider and use your own Request Class

Fortify::authenticateUsing(function (CustomFormRequestClass $request) {
        $user = User::where('email', $request->email)->first();

        if ($user &&
            Hash::check($request->password, $user->password)) {
            return $user;
        }
    });
3 likes
uniqueginun's avatar

this will give:

Argument 1 passed to App\Providers\FortifyServiceProvider::App\Providers\{closure}() must be an instance of App\Http\Requests\LoginRequest, instance of Laravel\Fortify\Http\Requests\LoginRequest given
1 like
sebastiano's avatar

i need just to add a new field to LoginRequest for google recaptcha.

'g-recaptcha-response'=>['required', new RecaptchaV2()],

Please or to participate in this conversation.