This package provides a simple reCAPTCHA v2 validation and blade directive to be user with Laravel applications.
Learn more about reCAPTCHA: https://developers.google.com/recaptcha/intro
You can install the package via composer:
composer require guiliredu/laravel-simple-recaptcha
After intalling the package, publish the config file with the command:
php artisan vendor:publish --provider=Guiliredu\LaravelSimpleRecaptcha\RecaptchaServiceProvider
This will place an recaptcha.php file in the config folder. You can now configure your .env file with the recaptcha parameters:
RECAPTCHA_KEY=...
RECAPTCHA_SECRET=...
You can use the blade files to include and render the recaptcha on your form. As today, this package has 2 ways to render the recaptcha:
Checkbox
This will render the classic "im not a robot" checkbox to the user to click.
@include('recaptcha::input')
You can pass and array of options as a second parameter to the include directive:
@include('recaptcha::input', ['size' => 'normal', 'theme' => 'light', 'tabindex' => 0, 'callback' => 'callback'])
Button
This will render a button with an invisible reCAPTCHA check - You will need to use a callback js function to submit the form.
@include('recaptcha::button', ['callback' => 'jsFunctionToCall'])
To validate the reCAPTCHA you can use our custom request rule:
class StoreController extends Controller
{
public function store(Request $request)
{
$this->validate($request,
['g-recaptcha-response' => 'recaptcha'],
['recaptcha' => trans('recaptcha::validation.invalid')]
);
}
}
We provide some helper methods to run simple validations:
use Guiliredu\LaravelSimpleRecaptcha\Recaptcha;
...
dd(Recaptcha::isRequestValid($request)); // true|false
dd(Recaptcha::isValid($request->input('g-recaptcha-response'))); // true|false
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please open an issue in this repo issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.