Laravel

Laravel 5 google reCaptcha

Laravel 5 google reCaptcha

Captcha is a most important thing for a website form to prevent spams, auto form submit and etc. Globally we can see lots of captcha library for open source development,
But most commonly using library is Google reCaptcha. Which is developed and maintaining by google team. Which is available for free of cost and most important thing is we can use
google recaptcha in both client and server side.

Normally google recaptcha embed for available for normal php also. There is tons of libraries available for laravel to embed captcha to the application. Here I have found one
Good Package to use Google reCaptcha for my application which is found at github.

https://github.com/anhskohbo/no-captcha 

Here Lets see how to use Google reCaptcha in Laravel 5.

Step 1 : Install anhskohbo/no-captcha package to your application.
Step 2 : Add Service Provider to Provider array in app.php
Step 3 : Generate NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY
Step 4 : Place NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY to you .env file
Step 5 : Embed to web page : {!! app(‘captcha’)->display() !!}

Step 1 : Install anhskohbo/no-captcha package to your application.

Run Below Command in your composer at your application directory

It will Install anhskohbo/no-captcha to your application

Step 2 : Add Service Provider to Provider array in app.php

You can find app.php file under config folder. config/app.php

And add anhskohbo/no-captcha Service Provider at Provider array.

Step 3 : Generate NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY

How to Generate NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY



We have google page to generate NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY  for your individual domains. Lets see how to do that.

Step 3.1 : Goto https://www.google.com/recaptcha/admin and Login with your gmail id and password.
Step 3.2 : You find “Get reCaptcha” button at top right and Click

reCaptcha-Step1
step 3.3 : Under Register a new site tab File your label name and Domain and Click Register Button.

reCaptcha-Step2
Step 3.4 : It will generate and give unique Site key and Secret Key.

reCaptcha-Step3

Step 4 : Place NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY  to you .env file

Now you got your Google reCaptcha NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY for your application. Place it in your .env file

Step 5 : Embed to web page :  {!! app(‘captcha’)->display() !!}

recaptcha
My Route :

My Controller : CaptchaController.php

My View : captcha.blade.php

To Validate Google Captcha, We have default reCaptcha Rule as “captcha” So you can use it as like in my controller.

recaptcha-form-after-submit

Hope it will help for someone.
Thanks for reading this article. If you like this don’t forget to share and comment.
Happy Coding!!!.