This repository contains simple reCAPTCHA v3 integration for your Laravel application.
You can install the package via composer:
composer require torralbodavid/simple-recaptcha-v3
- Set the following variables in your .env
Override xxxxx with your reCaptcha v3 keys. Get yours here
CAPTCHA_SITE_KEY=xxxxx
CAPTCHA_SECRET_KEY=xxxxx
Optionally, you can publish the config file of the package. You will be able to customize advanced settings, such as:
- Disabling reCaptcha v3
- Minimum score you should get in order to validate your form
- Hostname validation
- Hide reCaptcha badge
- Prefer navigator language on reCaptcha badge
php artisan vendor:publish --provider="Torralbodavid\SimpleRecaptchaV3\SimpleRecaptchaV3ServiceProvider" --tag=config
- To get started, you must include at the very bottom of your head tag from the pages you want to protect with reCaptcha, the
@captcha_init
blade directive. This will start loading Google reCAPTCHA API.
<html>
<head>
...
@captcha_init
</head>
</html>
- Include below your form initialization tag, the
@captcha('xxxx')
blade directive. Replace xxxx with your desired action.
<form method="..." action="...">
@captcha('login')
...
</form>
- To sum up, add the following rule on your form validation:
'recaptcha_response' => new Captcha
use Torralbodavid\SimpleRecaptchaV3\Rules\Captcha;
...
$request->validate([
...
'recaptcha_response' => new Captcha,
]);
You can customize reCaptcha v3 error messages by publishing the translations on your project.
php artisan vendor:publish --provider="Torralbodavid\SimpleRecaptchaV3\SimpleRecaptchaV3ServiceProvider" --tag=lang
You can customize @captcha and @captcha_init snippets by publishing the views on your project
php artisan vendor:publish --provider="Torralbodavid\SimpleRecaptchaV3\SimpleRecaptchaV3ServiceProvider" --tag=views
You can easily disable reCaptcha v3 integration in your tests by adding the following configuration on them
config()->set('simple-recaptcha-v3.active', false);
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Have fun!