RyanDaDeng / laravel-google-recaptcha-v3

It's probably the best Laravel Package for Google reCAPTCHA v3. Vue component supported.
MIT License
275 stars 40 forks source link

Struggling to implement on registration #74

Closed russ-sdg closed 3 years ago

russ-sdg commented 3 years ago

I'm guessing this is user error as I'm relatively new to Laravel. I am trying to use Recaptcha v3 on the standard registration form that comes with Laravel.

In the config file I have: 'setting' => [ [ 'action' => 'login', 'threshold' => 0.5, 'inline' => true, 'score_comparision' => false, ], [ 'action' => 'registration', 'threshold' => 0.5, 'inline' => true, 'score_comparison' => false, ], ],

In the blade I have all the normal fields plus:

@csrf ...
... {!! GoogleReCaptchaV3::render([ 'registration_id'=>'registration' ]) !!} In the controller I have: protected function validator(array $data) { return Validator::make($data, [ 'g-recaptcha-response' => [new GoogleReCaptchaV3ValidationRule('registration')], 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]); } What am I missing? Thanks!
ljanecek commented 3 years ago

You should add {!! GoogleReCaptchaV3::init() !!} into layout template, app.blade.php to the bottom.

https://github.com/RyanDaDeng/laravel-google-recaptcha-v3#add-google-api-script

russ-sdg commented 3 years ago

That did it. Thank you!

RyanDaDeng commented 3 years ago

better to check this sample code: https://github.com/RyanDaDeng/laravel-google-recaptcha-v3/wiki/Simple-Demo