Laravel Recaptcha Validator
, (*1)
Google reCAPTCHA Validator Package for Laravel Framework
Installation
Via Composer Require
You may install by running the composer require
command in your terminal:, (*2)
composer require vinkas/laravel-recaptcha
Configuration
Add Service Provider to your config/app.php
file, (*3)
Vinkas\Laravel\Recaptcha\ServiceProvider::class,
And run php artisan
command to publish package config file, (*4)
php artisan vendor:publish --provider="Vinkas\Laravel\Recaptcha\ServiceProvider"
Add your recaptcha site key and secret in .env
file, (*5)
RECAPTCHA_SITE_KEY=__________
RECAPTCHA_SECRET=__________
Add recaptcha custom error message in resources\lang\en\validation.php
file, (*6)
'recaptcha' => 'The capcha verfication failed. Please try again.',
Add recaptcha field in your form's blade view, (*7)
@if ($errors->has('g-recaptcha-response'))
{{ $errors->first('g-recaptcha-response') }}
@endif
Add Validator
calling function in your app controller file, (*8)
Validator::make($data, [
'g-recaptcha-response' => 'required|recaptcha',
]);
It's done! Now your form spam protected by Google reCAPTCHA!!!, (*9)
Dependencies
Google Recaptcha, (*10)