This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

CloudwaysCDN — a powerful solution that offers superior performance and satisfied global audience for your business. Read More

How to Use reCAPTCHA in Laravel 5.5 Forms for Validation

Updated on  4th August

4 Min Read
Reading Time: 4 minutes

*This blog post was updated on March 12, 2018

Forms are the main source of spam on any website. Whether it is the traditional contact forms or custom forms for user feedback, abusing the forms to (intentionally or unintentionally) overwhelm the server is a common attack on a website.

To counter this, Laravel 5.5 offers support for reCAPTCHA, an industry standard for preventing spam by greatly enhancing form validation capabilities. It is a combination of knowledge and image recognition-based interpretive response based on answer selection. The methodology relies on machine learning from Google’s large data sets of human interaction with the web, which is slightly different and random when compared to a bot.

recaptcha in laravel 5.5

In this article, I will demonstrate how to use Google reCAPTCHA for form validation in Laravel 5.5


This one requires only two things:

  • You must have some knowledge about Laravel 5.5.
  • You must have a launched Laravel app on Cloudways. Signup for a free account and follow this GIF for launching the app within minutes.

Get Necessary Packages

Let’s get the necessary classes we will require to make things possible. I’ll be using Composer to bring down the packages:

Set up Configurations

We are going to edit the app.php file.

Insert these lines in “providers” array:

Now, let’s setup our secret keys. Go to this link, and enter your domain address, like I have shown in image below, to grab your “secret key” and “site key”.

Make changes to your “.env” file:

Insert these lines:

Set up Routes

These are our entry points of our app, let’s make some changes.

Paste the code below:

Save and exit. As you see, our routes are accessing a FileController which has two functions to get and post captcha form.

Make the Controller

Let’s make our controller.

Copy and paste the code below:

Save and exit.

Make the Views

Let’s make our UI which will make us use of the reCAPTCHA service.

And, paste this code below.

Let’s save and exit

Let’s Test the Form

Go to your app link and let’s see if you can find the reCAPTCHA. Something like this image below:

That is it, guys! Have a good coding week!

Share your opinion in the comment section. COMMENT NOW

Noor Ali

Noor Ali is an Associate Software Engineer at Cloudways. He loves to solve technical problems through programming and mathematics.

Create Laravel apps without the worry of server management.

Deploy your app on optimized PHP hosting servers for Laravel.

Get Our Newsletter
Be the first to get the latest updates and tutorials.