reCAPTCHA is a free service from Google. It's a CAPTCHA-like system designed to
recognize that the user is human and, at the same time, assist in the digitization
of books. It helps to protects your website from spam and abuse.
If you're running the Laravel Project at your Local
Server. It's also acceptable for testing Google reCAPTCHA.
In this tutorial, You'll learn to integrate Google reCAPTCHA in your Laravel
Project. Follow the
step by step guide to create the application.
You can name the key and secret as you like. I have named them as RECAPTCHA_KEY,RECAPTCHA_SECRET
.It is required later in the validation form.
Create the Form Request Validaiton
Create the Custom Validation Rules using form request validation in by typing
the following command,
php artisan make:request ReCaptchaFormRequest
The generated class will be stored in in the app/Http/Requests file
directory. Open ReCaptchaFormRequest.php from the directory and add the
validation rules inside the rules method
class ReCaptchaFormRequest extends FormRequest
public function authorize()
public function rules()
Create the Custom Validation with Guzzle
If you don’t have Guzzle, Install it by typing the command below at your
composer require guzzlehttp/guzzle
After installing Guzzle, Create a directory as Validation, Inside the
Validation folder, Create a PHP file as ReCaptcha.php and add the
<?php namespace App\Validation;
public function validate($attribute, $value, $parameters, $validator)
$client = new Client();
$response = $client->post(
'secret' => env('RECAPTCHA_SECRET'),
'response' => $value
$body = json_decode((string)$response->getBody());
The next step is to register Validation in AppServiceProvider's Boot
public function boot()
Create the Captcha Controller
Type the following command at your terminal to create CaptchaController.php
file in controllers
php artisan make:controller CaptchaController
Create two methods as index and captcha in CaptchaController.
class CaptchaController extends Controller
public function index()
public function captcha(ReCaptchaFormRequest $reCaptchaFormRequest)
Create the Routes
In this step,
Go to 'routes->web.php' file and add the following code.