shamarkellman/laravel-recaptcha

laravel-recaptcha

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

This package is auto-updated.

Last update: 2024-04-25 21:37:45 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

68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f7061636b6167652d6c61726176656c2d7265636170746368612d6c61726176656c2e6a70673f743d31

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.