torralbodavid/simple-recaptcha-v3

Simple reCAPTCHA v3 integration

v1.5.0 2022-03-05 11:39 UTC

This package is auto-updated.

Last update: 2024-04-05 15:57:56 UTC


README

Latest Version on Packagist GitHub Workflow Status Quality Score Total Downloads

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

  1. 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
  1. 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>
  1. Include below your form initialization tag, the @captcha('xxxx') blade directive. Replace xxxx with your desired action.
    <form method="..." action="...">
        @captcha('login')
        ...
    </form>
  1. 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!