Laravel 7/6 Google ReCaptcha v2 Form Validation

In this tutorial you will learn about the Laravel 7/6 Google ReCaptcha v2 Form Validation and its application with practical example.

In this Laravel 7/6 Google ReCaptcha v2 Form Validation tutorial I’ll show you how to integrate google v2 ReCAPTCHA with laravel 7/6 forms. In this tutorial, we will implement google v2 recaptcha with form in laravel 7/6. We will be using google v2 Recaptcha in laravel to secure laravel forms against spam.

In this tutorial, we will integrate google recaptcha v2 in laravel 7/6 application. I’ll guide you through step by step how to integrate google recaptcha v2 in a laravel 7/6 application. We will be using ‘anhskohbo/no-captcha’ package for google recaptcha integration in laravel 7/6 application. In this tutorial, we will be creating a simple form with some basic fields along with the google recaptcha.

Laravel 7/6 Google ReCaptcha v2 Form Validation

In this step by step Laravel 7/6 Google ReCAPTCHA v2 Example Tutorial I’ll guide you through the process to integrate google recaptcha v2 in laravel 7/6.

  • Step 1: Download laravel Fresh Setup
  • Step 2: Setup Database Credentials
  • Step 3: Install Google Captcha Package
  • Step 4: Get Google Captcha Secrets
  • Step 5: Create Route
  • Step 6: Generate Controller by Command
  • Step 7: Create Blade View (form)
  • Step 8: Run Development Server

Step 1: Download laravel Fresh Setup

First of all we need to create a fresh laravel project, download and install Laravel using the below command

Step 2: Setup Database Credentials

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Install Google Captcha Package

We will be using ‘anhskohbo/no-captcha’ package for google recaptcha integration in laravel 5.8 application. In this step we will be installing “anhskohbo/no-captcha” via following composer command, lets open your terminal and switch to the project directory and enter the following command –

After successfully Install Google Captcha Packages, open config/app.php file and add service provider and alias.

Step 4: Get Google Captcha Secrets

Now, we need to set Google Site Key and Secret Key in .env file. Let’s start by getting Google key & secret required to make ReCaptcha authorize with the Google servers. Visit the following link to register your site –

Let’s open .env file and add this credential as following –

.env

Step 5: Create Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 6: Generate Controller by Command

Now, lets create a controller named CaptchaController using command given below –

Now open the controller let’s go to app/Http/Controllers/CaptchaController.php. Now create some methods for showing and storing data into a database.

Step 7: Create Blade View

In this step, we will create view/blade file to render a register form with recaptcha field. Lets create a “captchaform.blade.php” file in “resources/views/” directory and put the following code in it.

resources/views/captchaform.blade.php

Step 8: Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 7/6 Google ReCaptcha v2 Form Validation and its application with practical example. I hope you will like this tutorial.