2017 © Pedro Peláez
 

library laravel-recaptcha

Laravel package for Google's ReCAPTCHA service

image

noylecorp/laravel-recaptcha

Laravel package for Google's ReCAPTCHA service

  • Wednesday, June 29, 2016
  • by bicknoyle
  • Repository
  • 1 Watchers
  • 3 Stars
  • 2,751 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

Build Status, (*1)

Laravel Recaptcha

Laravel 5.1 package for Google reCAPTCHA, providing helper functions for creating reCAPTCHA fields and a service for validating responses., (*2)

Note: This package uses reCAPTCHA API version 2.0, (*3)

Installation

Install Laravel Recaptcha with composer:, (*4)

composer require noylecorp/laravel-recaptcha

Next, add the service provider to your config/app.php:, (*5)

'providers' => [
    // ...
    Noylecorp\Recaptcha\RecaptchaServiceProvider::class,
]

Next, publish the package configuration file to your application:, (*6)

php artisan vendor:publish --provider="Noylecorp\Recaptcha\RecaptchaServiceProvider"

The file recaptcha.php gets copied into your configuration directory. The final installation step is to add your reCAPTCHA site and secret keys to your .env file:, (*7)

RECAPTCHA_SITE_KEY=your-site-key
RECAPTCHA_SECRET_KEY=your-secret-key

If you don't have reCAPTCHA keys you can signs up for a pair here., (*8)

Usage

Creating a reCAPTCHA widget

Easily create reCAPTCHA widgets using the recaptcha() helper function:, (*9)

{!! recaptcha() !!}

// outputs...

<script src="https://www.google.com/recaptcha/api.js"></script>
<div class="g-recaptcha" data-sitekey="my-site-key"></div>

You can also pass in HTML attributes..., (*10)

{!! recaptcha(['id' => 'myrecaptcha']) !!}

...or any of reCAPTCHA's available options:, (*11)

{!! recaptcha(['theme' => 'dark']) !!}

{!! recaptcha(['data-theme' => 'dark']) !!} // same thing

If you need to render the <script> and <div> tags for the reCAPTCHA widget separately, you can use the recaptch_script() and recaptcha_widget() functions:, (*12)

{!! recaptcha_script() !!}

// ...

{!! recaptcha_widget() !!}

Need to support users without JavaScript? You can also insert a <noscript> fallback:, (*13)

{!! recaptcha() !!}
{!! recaptcha_noscript() !!}

Or, if you don't want to use any of those helper functions, you can use recaptcha_site_key() to grab the site key for your own custom markup:, (*14)

<div class="g-recaptcha" data-sitekey="{{ recaptcha_site_key() }}"></div>

Finally, if you have LaravelCollective Html installed, all helper functions can also be accessed through the Form facade:, (*15)

{!! Form::recaptcha() !!}

Validating reCAPTCHA responses

The simplest way to validate a reCAPTCHA field is by using the added recaptcha validation rule:, (*16)

// in a controller...
$this->validate($request, [
    'g-recaptcha-response' => 'required|recaptcha'
]);

// in a form request...
public function rules()
{
    return [
        'g-recaptcha-response' => 'required|recaptcha'
    ];
}

Or, you can access the service directly to do manual validation:, (*17)

if (app('recaptcha')->verify($request->input('g-recaptcha-response'))) {
    // user passed reCAPTCHA
}
else {
    // user failed reCAPTCHA
}

The Versions

29/06 2016

dev-master

9999999-dev

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha

15/06 2016

v0.4.1

0.4.1.0

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha

27/10 2015

v0.4.0

0.4.0.0

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha

14/10 2015

v0.3.1

0.3.1.0

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha

14/10 2015

v0.3.0

0.3.0.0

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha

13/10 2015

v0.2.1

0.2.1.0

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha

23/09 2015

v0.2.0

0.2.0.0

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha

18/09 2015

v0.1.1

0.1.1.0

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha

18/09 2015

v0.1.0

0.1.0.0

Laravel package for Google's ReCAPTCHA service

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nick Boyle

laravel recaptcha