daikazu / laravel-recaptcha
reCAPTCHA v2 and Invisible reCAPTCHA for laravel
v0.0.5
2019-10-04 20:42 UTC
Requires
- php: >=5.5.5
- guzzlehttp/guzzle: ~6.3
- illuminate/support: ~5.5|~6.0
Requires (Dev)
- phpunit/phpunit: 7.0.*
README
reCAPTCHA v2 and Invisible reCAPTCHA for Laravel
Easily add Google's V2 and Invisable reCaptcha to your forms;
This code is borrowed heavily from anhskohbo/no-captcha
Installation
composer require daikazu/laravel-recaptcha
Setup
NOTE This package supports Laravel 5.5 auto-discovery, so you can skip the setup if you are using 5.5 and above.
LARAVEL 5
Configuration
Public Config File recaptcha.php
php artisan vendor:publish --provider="Daikazu\LaravelRecaptcha\ReCaptchaServiceProvider"
Add your RECAPTCHA_SECRET
and RECAPTCHA_SITEKEY
into your .env
file:
RECAPTCHA_SECRET=secret-key
RECAPTCHA_SITEKEY=site-key
(You can obtain them from here)
Usage
Initialize javascript source:
With default options :
{!! ReCaptcha::renderJs() !!}
With language support or onloadCallback option :
{!! ReCaptcha::renderJs('fr', true, 'recaptchaCallback') !!}
Display reCAPTCHA V2
{!! ReCaptcha::displayWidget() !!}
With custom attributes (theme, size, callback ...) :
{!! ReCaptcha::displayWidget(['data-theme' => 'dark']) !!}
Display Invisible reCAPTCHA button
{!! ReCaptcha::displayButton( 'Button Text', ['data-callback' => 'onFormSubmit', 'class' => 'button is-info']) !!}
Validation
Add 'g-recaptcha-response' => 'required|recaptcha'
to to validation rules array;
$validate = Validator::make(Input::all(), [ 'g-recaptcha-response' => 'required|recaptcha' ]);
Then check for reCAPTCHA errors in the form:
@if ($errors->has('g-recaptcha-response')) <span class="help-block"> <strong>{{ $errors->first('g-recaptcha-response') }}</strong> </span> @endif
Testing
Comming soon!