Solution Timeline

All versions (edits) of solutions to need help implementing google recaptcha in Laravel app/w vue.js appear below in the order they were created. Comments that appear under revisions were those created when that particular revision was current.

To see the revision history of a single solution (with diffs), click on the solution number (ie. "#1") in the upper right corner of a solution revision below.

← Bounty Expand all edits

Have you included this line?

<script src='https://www.google.com/recaptcha/api.js'>
</script>

Also try changing your boot() to this

public function boot()
{
Validator::extend(
'recaptcha',
'App\\Validators\\Recaptcha@validate'
);

Kindly take a backup before making changes.

Hope it helps.

Hi, can you try this:

Create a new config value for recaptcha_secret_key and recaptcha_site_key in config/app.php or another custom config file.

And in the boot() like this:

Validator::extend('recaptcha', function ($attribute, $value, $parameters, $validator) {

$recaptcha = new ReCaptcha(config('app.recaptcha_secret_key'));

$resp = $recaptcha->verify($value, request()->ip());

return $resp->isSuccess();

});

Try if in that way it works.

I have tested you code on my computer.I mailed you the reason I think is causing the problem.Thank you

Hey, this is the final solution to your problem. I have tested this code and it worked.
open you EmailController class and set the constructor function to

public function __construct(Request $request)
    {   
        parse_str ( parse_url ( $request->headers->get('referer') , PHP_URL_QUERY ) , $params );
        $CAPTCHA=$params['g-recaptcha-response'];

        $request['g-recaptcha-response'] = $CAPTCHA;
    }

Also open you EmailRequest.php and set your rules(uncomment g-recaptcha-response line) to

public function rules()
    {
        return [
            'name' => 'required|max:100',
            'email' => 'required|email|max:100',
            'phone' => 'max:15',
            'message' => 'required|max:1500',
            'g-recaptcha-response'=>'required|recaptcha'
        ];
    }

Hey, this is the final solution to your problem. I have tested this code and it worked.
open you EmailController class and set the constructor function to

public function __construct(Request $request)
    {   
        parse_str ( parse_url ( $request->headers->get('referer') , PHP_URL_QUERY ) , $params );
        $CAPTCHA=$params['g-recaptcha-response'];

        $request['g-recaptcha-response'] = $CAPTCHA;
    }

Also open you EmailRequest.php and set your rules(uncomment g-recaptcha-response line) to

public function rules()
    {
        return [
            'name' => 'required|max:100',
            'email' => 'required|email|max:100',
            'phone' => 'max:15',
            'message' => 'required|max:1500',
            'g-recaptcha-response'=>'required|recaptcha'
        ];
    }

Hope it help and a tip would be appreciated.Thank you.

Hey, this is a quick fix to your problem. I have tested this code and it worked.
open you EmailController class and set the constructor function to

public function __construct(Request $request)
    {   
        parse_str ( parse_url ( $request->headers->get('referer') , PHP_URL_QUERY ) , $params );
        $CAPTCHA=$params['g-recaptcha-response'];

        $request['g-recaptcha-response'] = $CAPTCHA;
    }

Also open you EmailRequest.php and set your rules(uncomment g-recaptcha-response line) to

public function rules()
    {
        return [
            'name' => 'required|max:100',
            'email' => 'required|email|max:100',
            'phone' => 'max:15',
            'message' => 'required|max:1500',
            'g-recaptcha-response'=>'required|recaptcha'
        ];
    }

Hope it helps and a tip would be appreciated.Thank you.

100% working tested

Hey, this is a quick fix to your problem. I have tested this code and it worked.

open you EmailRequest.php and set your rules(uncomment g-recaptcha-response line) to

public function rules()
    {
        return [
            'name' => 'required|max:100',
            'email' => 'required|email|max:100',
            'phone' => 'max:15',
            'message' => 'required|max:1500',
            'g-recaptcha-response'=>'required|recaptcha'
        ];
    }

open Contact.vue and just above axios.post add

this.email.grecaptcha=grecaptcha.getResponse();

Hope it helps and a tip would be appreciated.Thank you.

100% working tested

Hey, this is a quick fix to your problem. I have tested this code and it worked.

1.open you EmailRequest.php and set your rules(uncomment g-recaptcha-response line) to

public function rules()
    {
        return [
            'name' => 'required|max:100',
            'email' => 'required|email|max:100',
            'phone' => 'max:15',
            'message' => 'required|max:1500',
            'g-recaptcha-response'=>'required|recaptcha'
        ];
    }

2 open Contact.vue and just above axios.post add

this.email.grecaptcha=grecaptcha.getResponse();

That's it.
Hope it helps and a tip would be appreciated.Thank you.

Winning solution Tipped