DEV Community

Cover image for Integrating Google re-Captcha In Laravel
Salman Abbas (سلیمان)
Salman Abbas (سلیمان)

Posted on

Integrating Google re-Captcha In Laravel

Hello!

The aim of this simple blog post is to give you the demonstration of how you can add google capthca verification in your laravel application.

Video link of this same post.
https://youtube.com/watch?v=KzWJDV00ITc&t

The package that we will going to use:
https://github.com/anhskohbo/no-captcha

Step #01:

Installing package

composer require anhskohbo/no-captcha
Enter fullscreen mode Exit fullscreen mode

Step # 02:

Go to app/config/app.php file of your project and then go to the providers array and add this class to the providers array.

Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class,
Enter fullscreen mode Exit fullscreen mode

Now, in the same file go to the aliases array and add this package aliase.

Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class,
Enter fullscreen mode Exit fullscreen mode

Now, Let's publish the config file.

php artisan vendor:publish --provider="Anhskohbo\NoCaptcha\NoCaptchaServiceProvider"
Enter fullscreen mode Exit fullscreen mode

Step # 03

Now let's configure this package, To configure this you need to add add NOCAPTCHA_SECRET and NOCAPTCHA_SITEKEY in .env file.

Go to the .env file and add these lines:

NOCAPTCHA_SECRET=secret-key
NOCAPTCHA_SITEKEY=site-key
Enter fullscreen mode Exit fullscreen mode

Now you need to generate these secret key and site key from google re-captcha form.

Link to generate google re-Captcha keys:
https://www.google.com/recaptcha/admin/create

This is the form here from where you can generate these keys.
If you are on a local-server so the below form fields will work great for you but if you are on a live server you just need to add your domain.

Image description

Step # 04

Now, we will see that how you can you display this re-captcha in the front-end part of your application.

<div>
 {!! NoCaptcha::renderJs() !!}
 {!! NoCaptcha::display() !!}
</div>
Enter fullscreen mode Exit fullscreen mode

By adding the above div in to the front end of your blade file, the re-captcha will be displayed.

I hope this blog will help you in any manner to learn how to add re-Captcha verification in your laravel application.

If you have any queries or questions or facing any problems, Feel free to mention here in the comment below.

Thanks!

Video Link :
https://youtube.com/watch?v=KzWJDV00ITc&t

Oldest comments (0)