Laravel Google Recaptcha – Today we will discuss how to use google re-captcha in laravel application. Basically, google Recaptcha is used to verify the user is human or robots.
Today we will integrate google Recaptcha in the laravel 6 application. We will create one form using google Recaptcha and before store data into the database, we will verify the form data using laravel validations.
In this google Recaptcha tutorial, we will complete all steps and after that, we will provide a live demo button. Click the live demo button and test this laravel google Recaptcha integration.
Contents
- Download laravel 6 Setup
- Setup Database Credentials
- Install Google Captcha Package
- Define Route
- Create Controller
- Create Blade View (form)
- Start Development Server
- Conclusion
Let’s Start Google V2 Recaptcha Form Validation Tutorial
Download laravel 6 Setup
First We need to Download fresh laravel 6 setups. Use the below command to download the laravel 6 fresh setup on your system.
composer create-project --prefer-dist laravel/laravel blog
Setup Database Credentials
After successfully download laravel 6 Application, Go to your project .env file and set up database credential and move next step :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=here your database name here
DB_USERNAME=here database username here
DB_PASSWORD=here database password here
Install Google Captcha Package
Now We will Install the Google Captcha Package in your laravel 6 application. Use the below command and install this package in your laravel application.
composer require anhskohbo/no-captcha
After successfully Install Google Captcha Packages, open config/app.php file and add service provider and alias.
config/app.php
'providers' => [
Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class
],
'aliases' => [
'NoCaptcha' => Anhskohbo\NoCaptcha\Facades\NoCaptcha::class,
]
Get Google Captcha Secrets
Now I will create google Recaptcha site_key and secret_key for showing the Recaptcha in laravel application. If you have already site_key and secret_key, so you need to put the .env file. If you don’t know where we will get secret_key and secret_site click below the link and create your own secret credentials. Recaptcha new site registration
When you click this link Recaptcha new site registration you will see the form look like. Here fill all the details and submit the form.

You will submit the above form after that you will see your secret_site and secret_key, Copy your credentials here and put your .env file

After that, we will set the google captcha secret in .env files, let’s open .env file and add this credentials here :
NOCAPTCHA_SITEKEY=secret_site_key
NOCAPTCHA_SECRET=secret_key
Create Route
Now We will add two routes in the web.php file as below. The first is showing form and second is store form data into the database.
Open routes/web.php file
Route::get('captcha-form', '[email protected]');
Route::post('store-captcha-form', '[email protected]');
Create Controller
We need to create new controller CaptchaController that will manage two methods. lets use this below command and create a Controller.
php artisan make:controller CaptchaController
Now open the controller let’s go to the => app/Http/Controllers/CaptchaController.php. Now create some methods for showing and storing data into a database.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Validator,Redirect,Response; use App\User; class CaptchaController extends Controller { public function captchaForm() { return view('captchaform'); } public function storeCaptchaForm(Request $request) { request()->validate([ 'name' => 'required', 'email' => 'required', 'mobile_number' => 'required', 'g-recaptcha-response' => 'required|captcha', ]); dd('successfully validate'); } }
Create Blade View
Next, create a captchaform.blade.php file in resources/views/ folder and copy-paste the following code.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="csrf-token" content="{{ csrf_token() }}"> <title>laravel 6 Google Recatpcha Verification - Tutsmake.com</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/additional-methods.min.js"></script> <style> .error{ color:red; } </style> </head> <body> <div class="container"> <h2 style="margin-top: 10px;" class="text-center">laravel 6 Google Recatpcha Verification - <a href="https://www.tutsmake.com" target="_blank">TutsMake</a></h2> <br><br><br> <div class="row justify-content-center"> <div class="col-md-8"> <a href="https://www.tutsmake.com/laravel-5-8-v2-google-recaptcha-integration" class="btn btn-secondary">Back to Post</a> <br><br> @if ($message = Session::get('success')) <div class="alert alert-success alert-block"> <button type="button" class="close" data-dismiss="alert">×</button> <strong>{{ $message }}</strong> </div> <br> @endif <form id="captcha-form" method="post" action="{{url('store-captcha-form')}}"> @csrf <div class="form-group"> <label for="formGroupExampleInput">Name</label> <input type="text" name="name" class="form-control" id="formGroupExampleInput" placeholder="Please enter name"> <span class="text-danger">{{ $errors->first('name') }}</span> </div> <div class="form-group"> <label for="email">Email Id</label> <input type="text" name="email" class="form-control" id="email" placeholder="Please enter email id"> <span class="text-danger">{{ $errors->first('email') }}</span> </div> <div class="form-group"> <label for="mobile_number">Mobile Number</label> <input type="text" name="mobile_number" class="form-control" id="mobile_number" placeholder="Please enter mobile number"> <span class="text-danger">{{ $errors->first('mobile_number') }}</span> </div> <div class="form-group"> <label for="captcha">Captcha</label> {!! NoCaptcha::renderJs() !!} {!! NoCaptcha::display() !!} <span class="text-danger">{{ $errors->first('g-recaptcha-response') }}</span> </div> <div class="form-group"> <button type="submit" class="btn btn-success">Submit</button> </div> </form> </div> </div> </div> </body> </html>
Start Development Server
We need to start the development server. Use the php artisan serve command and start your server :
php artisan serve
If you want to run the project diffrent port so use this below command
php artisan serve --port=8080
Now we are ready to run our example so run bellow command to quick run.
http://localhost:8000/ Or direct hit in your browser http://localhost/blog/public/captcha-form
Conclusion
In this laravel google Recaptcha tutorial, We have successfully created google Recaptcha credentials (secret_site and secret_key). After that, we have successfully integrated google Recaptcha in laravel based application.
If you have any questions or thoughts to share, use the comment form below to reach us.
cialis once a day pill Eraveden cheap cialis online fradrady Priligy 30 Mg Vademecum
Usually I don’t read article on blogs, however I wish to
say that this write-up very pressured me to check out and do so!
Your writing taste has been amazed me. Thanks, very great post.
Here is my homepage; cheap flights
Thanks for one’s marvelous posting! I genuinely enjoyed reading it, you are
a great author.I will ensure that I bookmark your blog and will eventually come back from now on. I want to encourage you to
ultimately continue your great posts, have a nice evening!
Feel free to surf to my blog post cheap flights
Hi! This is my 1st comment here so I just wanted to give a quick shout
out and tell you I really enjoy reading through your articles.
Can you recommend any other blogs/websites/forums that
deal with the same subjects? Thanks!
Also visit my web page; cheap flights
I pay a quick visit day-to-day a few websites and sites to read posts, but this web
site provides quality based posts.
Feel free to surf to my homepage – cheap flights – http://tinyurl.com/ –
Hey just wanted to give you a quick heads up and let you know
a few of the pictures aren’t loading properly.
I’m not sure why but I think its a linking issue. I’ve tried it in two
different internet browsers and both show the same results.
Also visit my website :: cheap flights
It’s going to be finish of mine day, but before end I am reading
this wonderful post to increase my knowledge.
My blog post: cheap flights (tinyurl.com)
diabetes international pharmacy online pharmacy reviews
i want to buy viagra online buy viagra online viagra for cheap on line
pharmacies near me canadian pharmaceuticals online reviews navarro pharmacy
buying prescription drugs canada blood pressure cheap drugs online
herbals general health northwest pharmacy/com
women’s health skin care mexican pharmacies online
overseas pharmacy forum buy viagra, canada national pharmacies online
on line viagra cheap mastercard therefore if traveling through europe you will need a separate visa to enter ireland. it is important to note, ordering viagra online buy viagra
viagrapills viagra substitute viagra prescrition for walgreens
brand cialis how much does cialis cost in canada overnight cialis delivery
cash advance sand springs oklahoma cash advance laredo texas cash money first loan
direct payday loans in texas what banks cash advance american express dubai money loan
payday loan saskatoon money shop loan default cash loans live oak fl
I just could not go away your site before suggesting
that I really loved the standard information an individual supply on your visitors?
Is going to be back continuously to check out
new posts
Feel free to visit my webpage :: cheap flights – tinyurl.com –
qual e a formula do cialis safest online pharmacy for cialis cialis anti estrogen
tarifs cialis en pharmacie cialis en bloeddruk dove posso acquistare cialis online
bdo jcb cash advance payday loans fast cash now payday loans in antioch ca
viagra singapore buy viagra on line viagra without
Very good written article
free robux
viagra generic viagra • cialis • for sale viagra australia