notix/gcaptcha

NOTIX - Google ReCaptcha for laravel

v1.0.1 2024-10-06 21:56 UTC

This package is auto-updated.

Last update: 2024-11-06 22:13:49 UTC


README

Latest Stable Version Total Downloads Monthly Downloads License

Instalation

composer require notix/gcaptcha

Configuration

Add CAPTCHA_SECRET, CAPTCHA_SITEKEY optionally CAPTCHA_THEME (default light)

CAPTCHA_SECRET=
CAPTCHA_SITEKEY=
#Optionally default is light theme.
CAPTCHA_THEME=

You can take the private key as well as the public key from this link)

Publish Config

php artisan vendor:publish --provider="Notix\GCaptcha\CaptchaServiceProvider"

Usage

Render captcha in '.blade.php'

{!! app('captcha')->display() !!}

Validation

Add 'g-recaptcha-response' => 'required|captcha' to rules array.

Or make custom messages..
Add this value to the 'custom' array in the 'validation' language file.
(Your laravel project > 'lang' > 'en' (or other language folder) > 'validation.php')

'custom' => [
    'g-recaptcha-response' => [
        'required' => 'Please confirm that you are not a robot.',
        'captcha' => 'There was a problem with captcha verification, please wait or contact the administrator.',
    ],
],

Display

To display error messages you can use the standard option where all errors are displayed together. (laravel docs)

@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

Or if you want to show errors directly above or below the captcha

@if($errors->has('g-recaptcha-response'))
    <div class="alert alert-danger">
        <strong>{{ $errors->first('g-recaptcha-response') }}</strong>
    </div>
@endif