shamarkellman/laravel-recaptcha

laravel-recaptcha

dev-master 2021-02-25 14:21 UTC

This package is auto-updated.

Last update: 2024-10-25 22:38:25 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require shamarkellman/laravel-recaptcha

You can publish the config file with:

php artisan vendor:publish --provider="ShamarKellman\LaravelRecaptcha\LaravelRecaptchaServiceProvider" --tag="laravel-recaptcha-config"

This is the contents of the published config file:

return [
    'public_key' => env('GOOGLE_CAPTCHA_PUBLIC_KEY'),
    'private_key' => env('GOOGLE_CAPTCHA_PRIVATE_KEY'),
    'score_threshold' => 0.5,
];

Usage

First of all you have to create your own API keys here

Follow the instructions and at the end of the process you will find Site key and Secret key. Keep them close..you will need soon!

In your .env file you need to set the GOOGLE_CAPTCHA_PUBLIC_KEY and GOOGLE_CAPTCHA_PRIVATE_KEY

GOOGLE_CAPTCHA_PUBLIC_KEY=your_site_key
GOOGLE_CAPTCHA_PRIVATE_KEY=your_site_secret_key

The package contains blade directives and views. You can use either method to add the ReCaptcha to your site.

Method 1 - Blade Directive

  • The input directive should be added to your form
<form>
    @csrf
    @recaptchaInput
    
    ... other form feilds
    
</form>

(optional) you can add the Recaptcha branding your site using @recaptchaBranding

  • add the script directive to the bottom just before the end of the body tag
@recaptchaScripts
  • Add validation rule in your form request or validation function
use ShamarKellman\LaravelRecaptcha\Rules;

[
    //...other rules,
    'recaptcha_token' => ['required', new  ReCaptchaRule],
];
  • You can display the error message
@error('recaptcha_token')
    {{ $message }}
@enderror

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.