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

rameezisrar's avatar

Redirection failure on captcha

I am using the laravel registration form. On the RegisterController I am checking the response body. On captcha failure, I am trying to redirect the user to the register page. Pretty simple right? Here is the code

  $response  = Zttp::asFormParams()->post('https://www.google.com/recaptcha/api/siteverify',[
            'secret' => config('services.recaptcha.secret'),
            'response' => $data['g-recaptcha-response'],
            'remoteip' => $_SERVER['REMOTE_ADDR']
        ]);
        
        $response_body = json_decode($response->getBody(), true);
        
        
        if($response_body['success'] == false){ // redirect and abort
    
            
            return redirect()->route('register');
        }

On the captcha failure instead of simpy redirecting, it throws the following error:

Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Http\RedirectResponse given, called in 

I just want to redirect to the register page

0 likes
7 replies
YeZawHein's avatar

Model needs to implement theIlluminate\Contracts\Auth\Authenticatableinterface

use Illuminate\Contracts\Auth\Authenticatable

class YourClass extends Model implements Authenticatable
{
    
}
1 like
rameezisrar's avatar
rameezisrar
OP
Best Answer
Level 18

I created a custom validation rule to tackle this. Finally, it worked :) @z

MonsieurRado's avatar

Hello Rameezisrar,

Can you tell me how did you solved this issue please?

I have the same problem.

Thanks :)

rameezisrar's avatar

Just create a custom validation rule and add the redirection over there

MonsieurRado's avatar

thank you for your answer.

it works when the issue is due to "time out", the user can then submit the form again and it's ok.

but when the problem is due to double click (duplicate issue) , when the user submit the form again, then it shows the 419 error. Because the csrf token is not good anylonger.

sorry for my english, i hope you'll understand...

1 like
MonsieurRado's avatar

edit:

i solved the problem by adding js script to prevent the double click.

function DisableButton(b) { b.disabled = true; b.value = 'Submitting'; b.form.submit(); }
1 like

Please or to participate in this conversation.