Laravel 8 Add Captcha In Forms

In this tutorial you will learn about the Laravel 8 Add Captcha In Forms and its application with practical example.

n this Laravel 8 Add Captcha In Forms tutorial I’ll show you how to add or integrate captcha verification in laravel forms. In this tutorial you will learn to add captcha verification in laravel form. We will be using laravel captcha package to secure laravel forms against spamming. In this article we will be creating a simple form with some basic fields along with the captcha verification field.

What Is Captcha?

Captcha Verification is a common technique used in web forms to help to prevent spamming. Captcha helps to ensure that user is real humans and not a bot program to spam your forms. The user is somehow challenged to prove that they are human being.

Laravel 8 Add Captcha In Forms

In this step by step tutorial I will demonstrate you with example on how to add captcha verification field in laravel form. Please follow instruction given below:

  • Step 1 – Download Laravel 8 Application
  • Step 2 – Setup Database with App
  • Step 3 – Install Captcha Package
  • Step 4 – Register Captcha Package
  • Step 5 – Captcha Configuration
  • Step 6 – Create Form Routes
  • Step 7 – Create Form Controller By Artisan Command
  • Step 8 – Create Form Blade File
  • Step 9 – Run Development Server

Step 1 – Download Laravel 8 Application

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

Step 2 – Setup Database with App

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 Captcha Package

In this step, we will install laravel captcha Package via the composer dependency manager. Use the following command to install laravel captcha Package.

Step 4 – Register Captcha Package

In this step we will register captcha package in laravel application. So, Open providers/config/app.php file and register the captcha service provider and aliases.

Step 5 – Captcha Configuration

Now, open config/captcha.php file and enable or disable settings based on your requirement:

Step 6 – Create Routes

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 7 – Create Form Controller By Artisan Command

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

Now, go to app/http/controllers and open CaptchaValidationController.php file. And update the following code into it:

Step 8 – Create Blade File

Now, create blade view file to display form with captcha field and submit to database. Go to resources/views and create form-with-captcha.blade.php and update the following code into it:

The following below code will display validation error message on blade view file:

Step 9 – 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 8 Add Captcha In Forms and its application with practical example. I hope you will like this tutorial.