torralbodavid / simple-recaptcha-v3
Simple reCAPTCHA v3 integration
Requires
- php: ^7.3|^8.0
- illuminate/support: ^6.6.2|^7.0|^8.0|^9.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0
- phpunit/phpunit: ^9.4
README
This repository contains simple reCAPTCHA v3 integration for your Laravel application.
Installation
You can install the package via composer:
composer require torralbodavid/simple-recaptcha-v3
Usage
- 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, ]);
Customize error messages
You can customize reCaptcha v3 error messages by publishing the translations on your project.
php artisan vendor:publish --provider="Torralbodavid\SimpleRecaptchaV3\SimpleRecaptchaV3ServiceProvider" --tag=lang
Customize snippets
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
Disable reCaptcha v3 integration in tests
You can easily disable reCaptcha v3 integration in your tests by adding the following configuration on them
config()->set('simple-recaptcha-v3.active', false);
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email davidtorralboperez@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Have fun!