notix / gcaptcha
NOTIX - Google ReCaptcha for laravel
Installs: 20
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/notix/gcaptcha
Requires
- php: >=5.4.0
- google/recaptcha: 1.*
- illuminate/support: 5.*|6.*|7.*|8.*|9.*|10.*|11.*
README
Instalation
composer require notix/gcaptcha
Configuration
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)
Publish Config
php artisan vendor:publish --provider="Notix\GCaptcha\CaptchaServiceProvider"
Usage
Render captcha in '.blade.php'
{!! app('captcha')->display() !!}
Validation
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.', ], ],
Display
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