• Cryptocurrency
  • Earnings
  • Enterprise
  • About TechBooky
  • Submit Article
  • Advertise Here
  • Contact Us
TechBooky
  • African
  • AI
  • Metaverse
  • Gadgets
Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
  • African
  • AI
  • Metaverse
  • Gadgets
Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
TechBooky
Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Home Tips

How To Generate Google Recaptcha Code In Laravel?

Contributor by Contributor
July 9, 2019
in Tips
Share on FacebookShare on Twitter

Recaptcha is an automatic captcha recognition service designed for the needs of webmasters and website owners. They use it on websites in order to distinguish real people from spambots. For website designers, developers, admins, such a “pass system” is simply irreplaceable as it helps them to stop the unwanted traffic to the site. These days, the Laravel application is being used by many companies. If you are a Laravel Developer and want to generate Google Recaptcha code in Laravel, let’s follow the recommendations below:

  • Configure Laravel Application

You can install a new Laravel Application by using the following command.

composer create-project –prefer-dist laravel/laravel laravelrecaptcha

  • Install anhskohbo/no-captcha Package 

At first, you need to install anhskohbo/no-captcha Package for Google Recaptcha code. It will help you to generate a reCaptcha code for your application. Navigate to the command line and use the following command line.

composer require anhskohbo/no-captcha

  • Publish Configure File

It supports the auto-discovery feature of Laravel 5.5+. So, to do so, use the following command to Publish Config File-

php artisan vendor:publish –provider=”Anhskohbo\NoCaptcha\NoCaptchaServiceProvider”

  1. Set Google Site Key and Secret Key

Now, you should set Google Site Key and Secret Key in the .env file. If you have no Site Key and Secret Key, generate it from using this link.

Now, you need to open a .env file and add two keys:

NOCAPTCHA_SECRET=xxxx

NOCAPTCHA_SITEKEY=xxxx

  1. Develop One Controller

Use the following code to create one controller-

php artisan make:controller RecaptchaController –resource.

You also need to define validation in the controller file.

//RecaptchaController.php

public function create()

    {

        return view(‘recaptchacreate’);

    }

  public function store(Request $request)

    {

        $request->validate([

            ‘name’ => ‘required’,

            ’email’ => ‘required|email’,

            ‘password’ => ‘required|min:6’,

            ‘g-recaptcha-response’ => ‘required|captcha’

        ]);

        return “success”;

    }

In tore() function, put the validation. In case this process fails, it will show an error.

  1. Define Routes

You must explore the route in routes  >>  web.php file.

//web.php

Route::get(‘recaptchacreate’, ‘RecaptchaController@create’);

Route::post(‘store’, ‘RecaptchaController@store’);

You should define  Two(2) routes in the web.php file. The first route is to display the login page. And, the second route is used to make a post request.

  1. Create One View File

You need to create a file in the resources  >>  views  >>   recaptchacreate.blade.php and place the code in it:

//recaptchacreate.blade.php

<html lang=”en”>

<head>

    <title>reCAPTCHA Code in Laravel</title>

    <link rel=”stylesheet” href=”{{asset(‘css/app.css’)}}”>

    <link href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css” rel=”stylesheet”>  

    <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js”></script> 

    <script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js”></script> 

</head>

<body>

<div class=”container”>

      <h2>reCAPTCHA Code in Laravel</h2><br/>

      @if ($errors->any())

      <div class=”alert alert-danger”>

          <ul>

              @foreach ($errors->all() as $error)

                  <li>{{ $error }}</li>

              @endforeach

          </ul>

      </div><br />

      @endif

      <form method=”post” action=”{{url(‘store’)}}”>

        @csrf

        <div class=”row”>

          <div class=”col-md-4″></div>

          <div class=”form-group col-md-4″>

            <label for=”Name”>Name:</label>

            <input type=”text” class=”form-control” name=”name”>

          </div>

        </div>

        <div class=”row”>

          <div class=”col-md-4″></div>

            <div class=”form-group col-md-4″>

              <label for=”Email”>Email:</label>

              <input type=”text” class=”form-control” name=”email”>

            </div>

          </div>

        <div class=”row”>

          <div class=”col-md-4″></div>

            <div class=”form-group col-md-4″>

              <label for=”Password”>Password:</label>

              <input type=”password” class=”form-control” name=”password”>

            </div>

          </div>

        <div class=”row”>

          <div class=”col-md-4″></div>

          <div class=”form-group col-md-4″>

          <label for=”ReCaptcha”>Recaptcha:</label>

          {!! NoCaptcha::renderJs() !!}

          {!! NoCaptcha::display() !!}

            </div>

        </div>

          <div class=”col-md-4″></div>

          <div class=”form-group col-md-4″>

            <button type=”submit” class=”btn btn-success”>Submit</button>

          </div>

        </div>

      </form>

    </div>

</body>

</script>

</html>

Now, you need to develop the Laravel server by using the below-mentioned command:

PHP artisan serve

If you enter incorrect reCaptcha code, then it will show errors-

Now, you have successfully generated the Google Recaptcha code in Laravel.

Final Words

So, it is clear that Recaptcha is used by website owners to differentiate between bots and human users. You can generate Google Recaptcha code in Larvel in an easy way. Best of Luck!

Author Bio

Jack Calder is a WordPress Developer, associated with Stellen Infotech one of the best Web Development & Digital Marketing Company around the globe. He has a lot of experience in development custom WordPress Themes. He has delivered a numerous range of quality Websites related to WordPress. She has a strong passion for writing useful and insights about WordPress tips and tricks.

Related Posts:

  • What Is Off-Page SEO And How Can You Benefit from It ?
    What Is Off-Page SEO And How Can You Benefit from It ?
  • google_logo_1
    Google Building A Shielded Email Feature to Help…
  • web traffic1
    Top 5 For Free Testing Of Traffic Generation Service
  • GitHub Incorporates GPT-4 Chatbot To Complete The Copilot X Code Snippet Generator.
    GitHub Incorporates GPT-4 Chatbot To Complete The…
  • Digital Cloud Networking
    Demystifying Serverless Computing: Understanding And…
  • io2023logo
    Google Introduces AI Coding Bot For Android Developers
  • linebet
    LineBet Application – Your Bets Are Just A Few Taps Away!
  • mostbet app
    Here's What To Know About The Mostbet App In India

Discover more from TechBooky

Subscribe to get the latest posts sent to your email.

Tags: codedevelopergooglegoogle recaptchalaravellaravel developerlaravel programmingrecaptcharesearchtipstutorialwebsite
Contributor

Contributor

Posts by contributors. You can send in a post to be reviewed and published to info@techbooky.com

Quick Links

  • About TechBooky
  • Advertise Here
  • Contact us
  • Submit Article
  • Privacy Policy

Recent News

Truecaller Filters Verified Business Messages

Truecaller Filters Verified Business Messages

May 12, 2025
ChatGPT Deep Research Now Links to GitHub Repos

ChatGPT Deep Research Now Links to GitHub Repos

May 12, 2025
Microsoft Offers Guide to Fix Windows Blue Screen Errors

Microsoft Offers Guide to Fix Windows Blue Screen Errors

May 12, 2025
The NCC Commissioned MTNN To Lease Spectrums From NTEL And Renew Its 3G Spectrum

We’ve Invested $10b in Nigeria so Far – MTN

May 12, 2025
Tech Hype vs. Reality – When Big Tech Missed the Mark Pt. 1

Tech Hype vs. Reality – When Big Tech Missed the Mark Pt. 3

May 11, 2025
Google’s Antitrust Showdown, AI vs. Search, and other Headlines

Google’s Antitrust Showdown, AI vs. Search, and other Headlines

May 11, 2025
  • Login

© 2021 Design By Tech Booky Elite

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
  • African
  • Artificial Intelligence
  • Gadgets
  • Metaverse
  • Tips
  • About TechBooky
  • Advertise Here
  • Submit Article
  • Contact us

© 2021 Design By Tech Booky Elite

Discover more from TechBooky

Subscribe now to keep reading and get access to the full archive.

Continue reading

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok