composer require notix/gcaptcha
Add CAPTCHA_SECRET
, CAPTCHA_SITEKEY
optionally CAPTCHA_THEME
(default light)
CAPTCHA_SECRET=
CAPTCHA_SITEKEY=
#Optionally default is light theme.
CAPTCHA_THEME=
You can take the private key as well as the public key from this link)
php artisan vendor:publish --provider="Notix\GCaptcha\CaptchaServiceProvider"
{!! app('captcha')->display() !!}
Add 'g-recaptcha-response' => 'required|captcha'
to rules array.
Or make custom messages..
Add this value to the 'custom'
array in the 'validation'
language file.
(Your laravel project > 'lang'
> 'en'
(or other language folder) > 'validation.php'
)
'custom' => [
'g-recaptcha-response' => [
'required' => 'Please confirm that you are not a robot.',
'captcha' => 'There was a problem with captcha verification, please wait or contact the administrator.',
],
],
To display error messages you can use the standard option where all errors are displayed together. (laravel docs)
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
Or if you want to show errors directly above or below the captcha
@if($errors->has('g-recaptcha-response'))
<div class="alert alert-danger">
<strong>{{ $errors->first('g-recaptcha-response') }}</strong>
</div>
@endif