Package

Greggilbert Recaptcha

reCAPTCHA Validator for Laravel 5

Package

greggilbert/recaptcha

View on GitHub →

Abandoned

All good things must come to an end. The sad fact is that I don't have time to maintain this package, so the release of Laravel 6 is as good as any to make a clean break. You should take a look at the forks to see if anyone is carrying on the torch.

Thanks to everyone for sticking by this package for years!

Recaptcha

A reCAPTCHA Validator for Laravel 5.

(Looking for a Laravel 4 version? Pull the latest 1.x tag. For Laravel 5.0, pull the latest 2.0 tag.)

Installation

Add the following line to the require section of composer.json:

{
    "require": {
        "greggilbert/recaptcha": "dev-master"
    }
}

Setup

  1. In /config/app.php, add the following to providers:
Greggilbert\Recaptcha\RecaptchaServiceProvider::class,

and the following to aliases:

'Recaptcha' => Greggilbert\Recaptcha\Facades\Recaptcha::class,
  1. Run php artisan vendor:publish --provider="Greggilbert\Recaptcha\RecaptchaServiceProvider".
  2. In /config/recaptcha.php, enter your reCAPTCHA public and private keys.
  • If you are not using the most recent version of reCAPTCHA, set version to 1.
  • If you are upgrading to v2 of reCAPTCHA, note that your keys from the previous version will not work, and you need to generate a new set in the reCAPTCHA admin.
  1. The package ships with a default validation message, but if you want to customize it, add the following line into resources/lang/[lang]/validation.php:
    'recaptcha' => 'The :attribute field is not correct.',

Usage

v2 (No Captcha)

  1. In your form, use {!! Recaptcha::render() !!} to echo out the markup.
  2. In your validation rules, add the following:
    $rules = [
        // ...
        'g-recaptcha-response' => 'required|recaptcha',
    ];

v1 (Legacy)

  1. In your form, use {!! Recaptcha::render() !!} to echo out the markup.
  2. In your validation rules, add the following:
    $rules = [
        // ...
        'recaptcha_response_field' => 'required|recaptcha',
    ];

It's also recommended to add required when validating.

Customization

reCAPTCHA v2 allows for customization of the widget through a number of options, listed at the official documentation. You can configure the output of the captcha through six allowed keys: theme, type, lang, callback, tabindex and expired-callback.

In the config file, you can create an options array to set the default behavior. For example:

    // ...
    'options' => [
		'lang' => 'ja',
	],

would default the language in all the reCAPTCHAs to Japanese. If you want to further customize, you can pass options through the render option:

echo Recaptcha::render([ 'lang' => 'fr' ]);

Options passed into Recaptcha::render will always supercede the configuration.

Language

To change the language of the captcha, simply pass in a language as part of the options:

    'options' => [
        'lang' => 'fr',
	],

For a list of valid language codes, consulting the official documentation.

Custom template

Alternatively, if you want to set a default template instead of the standard one, you can use the config:

    // ...
    'template' => 'customCaptcha',

or you can pass it in through the Form option:

echo Recaptcha::render([ 'template' => 'customCaptcha' ]);

v1 customization

For the v1 customization options, consult the old documentation and apply accordingly.

Limitation

Because of Google's way of displaying the reCAPTCHA, this package won't work if you load your form from an AJAX call. If you need to do it, you should use one of the alternate methods provided by Google.

Greggilbert Recaptcha Related Articles

reCAPTCHA Packages for Laravel image

reCAPTCHA Packages for Laravel

Read article
Invisible reCAPTCHA Integration with Laravel image

Invisible reCAPTCHA Integration with Laravel

Read article
Google reCaptcha Enterprise Package for Laravel image

Google reCaptcha Enterprise Package for Laravel

Read article
Laravel No CAPTCHA reCAPTCHA image

Laravel No CAPTCHA reCAPTCHA

Read article
Add Spam Prevention to Laravel Apps with Honey image

Add Spam Prevention to Laravel Apps with Honey

Read article
5 Ways of Battling Form Spam image

5 Ways of Battling Form Spam

Read article

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing