Google reCAPTCHA v3 is a new mechanism to verify whether the user is a bot or not. It has been designed for potential users, site owners that want more data about their traffic. Google reCAPTCHA v3 returns a score for each request without user friction. The score is based on interactions with your site and allows you to take appropriate action for your site. Register reCAPTCHA v3 keys here.
You can also visit this:
RyanDaDeng introduced a Laravel Package for Google reCAPTCHA V3 that has the following features.
This package requires the following dependencies:
You can install it via composer:
$ composer require timehunter/laravel-google-recaptcha-v3 "~2.4.3" -vvv
If your Laravel framework version is less than or equal to Laravel 5.4, then please register the service provider under your config file: /config/app.php, otherwise please skip it.
'providers'=[ ...., TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider::class ]
'aliases'=[ ...., 'GoogleReCaptchaV3'=> TimeHunter\LaravelGoogleReCaptchaV3\Facades\GoogleReCaptchaV3::class ]
If your Laravel framework version is greater than or equals to laravel 5.5, just run the following command to publish config.
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.config
For vue component you’ve to run this command:
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.vuejs
After installation, you should see a googlerecaptchav3.php in your app/config folder, and a vue component under js/components/googlerecaptchav3 folder.
For multi lang you’ve to run this command:
$ php artisan vendor:publish --provider="TimeHunter\LaravelGoogleReCaptchaV3\Providers\GoogleReCaptchaV3ServiceProvider" --tag=googlerecaptchav3.lang
A lang folder will be created under /resources/lang/vendor/GoogleReCaptchaV3/
Setting up your Google reCAPTCHA details in the config file
You have to register all details in the config for host_name, site_key, secret_key, and site_verify_url.
Register credentials in .env:
Specify your Score threshold and action in ‘setting’, e.g.
'setting' = [ [ 'action' => 'contact_us', // Google reCAPTCHA required paramater 'threshold' => 0.2, // score threshold 'score_comparision' => false // if this is true, the system will do score comparsion against your threshold for the action ], [ 'action' => 'signup', 'threshold' => 0.2, 'score_comparision' => true ], ]
Note: if you want to enable Score Comparision, you also need to enable is_score_enabled to be true.
... 'is_score_enabled' = true ...
For Blade & Vue Usage you can view its detailed documentation on Github.
Published at : 04-08-2021
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.