Laravel 8 Google ReCAPTCHA v2 Example Tutorial

In this tutorial you will learn about the Laravel 8 Google ReCAPTCHA v2 Example Tutorial and its application with practical example.

In this Laravel 8 google ReCAPTCHA v2 form validation tutorial I’ll show you how to integrate  google v2 ReCAPTCHA with laravel 8 forms. In this tutorial, we will implement google v2 recaptcha with form in laravel 8. We will be using google v2 Recaptcha in laravel to secure laravel forms against spam.

Laravel 8 Google ReCAPTCHA v2 Example Tutorial

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

  • Install Laravel 8 Application
  • Configure Database Details
  • Install Google Recaptcha Package (anhskohbo/no-captcha)
  • Create Controller
  • Create Routes
  • Create Blade File
  • Start Development Server
  • Run This App On Browser

Install Laravel 8

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

Configure Database In .env file

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.

Install Google reCaptcha v2 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 –

This package is supports the auto-discovery feature so we need to only publish config file

Add Google Site Key and Secret Key

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

Create Controller

Now, lets create UserController using following command

Once the above command executed, it will create a controller file UserController.php in app/Http/Controllers/ directory. Open the UserController.php file and put the following code in it.

Controllers/UserController.php

Create Route

After this, we need to add following routes in “routes/web.php” to display form. Lets open “routes/web.php” file and add following route.

routes/web.php

Create Blade File

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

resources/views/create.blade.php

Start 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 –

http://localhost:8000/users

In this tutorial we have learn about the Laravel 8 Google ReCAPTCHA v2 Example Tutorial and its application with practical example. I hope you will like this tutorial.