Implement google recaptcha in laravel

Introduction

Google recaptcha reduces the bot and spam . Today we are going to Implement Google Recaptcha in Laravel . First we need to register for Google Recaptcha , click the link and register your key and secret . ūüôā

After registering, let’s create a two env element one for the key and another one for the secret key .

After setting up the recaptcha key and secret, we will create a new validator class namely Recaptcha or the name you prefer .

Create a new folder inside app directory Validators or the name you prefer and save above class. This class verify our recaptcha key. You can save the recaptcha form as you like. I prefer creating reusable includes file.

You can create includes file or paste the above code directly to the place you prefer. Paste the below code in AppServiceProvider boot function :

Now, Let’s create a request class . Enter the given below command in the terminal .

php artisan make:request CheckRecaptcha

Now you’re ready to go . Just use this method :

Happy Coding ūüôā

Sharing is caring!

Related Post