buyownex/recaptcha

A Laravel 5.5 package providing support for reCAPTCHA.

Installs: 46

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/buyownex/recaptcha

1.1 2020-04-25 23:17 UTC

This package is auto-updated.

Last update: 2025-12-26 12:07:36 UTC


README

A Laravel 5.5 package for working with reCAPTCHA. Enjoy!

demo

Installation

composer require BuyOwnEx/recaptcha
./artisan vendor:publish --provider "Ilya\Recaptcha\RecaptchaServiceProvider"

Usage

First, edit the published config file config/recaptcha.php (tip: use env variables to hide keys from source control).

Then, in your controller:

use Ilya\Recaptcha\RecaptchaRule as Recaptcha;

// in a method...
$data = request()->validate([
    recaptcha_input() => ['required', new Recaptcha],
    // or...
    recaptcha_input() => ['required', new Recaptcha('key_pair_name')],

    // your other stuff here...
]);

On the client side, use recaptcha_script() to load the necessary JS code, and use recaptcha() or recaptcha('key_pair_name') to render the reCAPTCHA itself. Example:

<body>
    <form method="POST" action="...">
        {{ csrf_field() }}
        {{ recaptcha() }}

        <button>Send</button>
    </form>

    {{ recaptcha_script() }}
</body>

Also, to make error messages more friendly, add the following code to the custom section of your validation.php language file (resources/lang/en/validation.php if assuming that you're using the en locale):

'custom' => [
    // other stuff...

    recaptcha_input() => [
        'required' => 'Failed the reCAPTCHA test.',
    ],
],

Additional Information

MIT license.