Current Location: Home> Latest Articles> Laravel Integration with Geetest CAPTCHA: Complete Installation and Configuration Guide

Laravel Integration with Geetest CAPTCHA: Complete Installation and Configuration Guide

gitbox 2025-07-15

Preparation Work

Before integrating Laravel with Geetest CAPTCHA, we need to complete some preparation tasks.

Create a Laravel Project

First, create a Laravel project in your local environment by running the following command:

composer create-project --prefer-dist laravel/laravel geetest-demo

This will create a Laravel project named geetest-demo.

Install Geetest CAPTCHA

Next, install the Geetest CAPTCHA Laravel plugin by running the following command in the project root directory:

composer require geetest-laravel/geetest-laravel

This will add the necessary dependencies for Geetest to the project.

Configure Geetest CAPTCHA

Once the preparation work is complete, we can begin configuring Geetest CAPTCHA.

Add Service Provider

In the config/app.php file, find the providers array and add the following line of code:

GeetestLaravel\GeetestLaravelServiceProvider::class,

This will register the Geetest CAPTCHA service provider.

Add Configuration File

Run the following command to generate the configuration file:

php artisan vendor:publish --provider="GeetestLaravel\GeetestLaravelServiceProvider"

After running the command, a geetest.php file will be generated in the config directory.

Configure ID and KEY

Open the geetest.php file and locate the id and key fields, and set them to the ID and KEY you obtain from Geetest's official website:

'id' => 'Your ID',
'key' => 'Your KEY',

Replace Your ID and Your KEY with the actual ID and KEY you received from Geetest.

Using Geetest CAPTCHA in Views

Now, let’s use Geetest CAPTCHA in the Laravel views.

Display CAPTCHA

To display the CAPTCHA in a form, use the following code:

@if(geetest_captcha())
    {!! geetest_init() !!}
@endif

This code will display the CAPTCHA input box and the verify button.

Verify CAPTCHA

When the form is submitted, we need to validate the user’s CAPTCHA input. You can do this using the following code:

$validatedData = $request->validate([
    'geetest_challenge' => 'required|geetest',
]);

This code will verify the user’s CAPTCHA. If the validation is successful, the next steps will continue.

Conclusion

With that, you’ve successfully integrated Geetest CAPTCHA into your Laravel project. In this article, we walked through how to create a project, install the plugin, configure Geetest, and use CAPTCHA in views for user validation. We hope this guide was helpful!