| Package Data | |
|---|---|
| Maintainer Username: | CrazyInventor |
| Maintainer Contact: | david@crazyinventor.net (David Schneider) |
| Package Create Date: | 2015-09-25 |
| Package Last Update: | 2017-04-26 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-22 15:00:42 |
| Package Statistics | |
|---|---|
| Total Downloads: | 739 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 2 |
| Total Watchers: | 2 |
| Total Forks: | 1 |
| Total Open Issues: | 0 |
Recaptcha v2 for Laravel 5. Inspired by anhskohbo/no-captcha and greggilbert/recaptcha.
Run 'composer require crazyinventor/laravel5-recaptcha2' or modify your composer.json:
{
"require": {
"crazyinventor/laravel5-recaptcha2": "1.0.1"
}
}
Get your keys for recaptcha from the admin page.
Then register the Service Provider.
In /config/app.php, add the following to providers:
'CrazyInventor\Lacaptcha\LacaptchaServiceProvider',
and the following to aliases:
'Recaptcha' => 'CrazyInventor\Lacaptcha\Facades\Lacaptcha',
In /config/app.php, add the following to providers:
CrazyInventor\Lacaptcha\LacaptchaServiceProvider::class,
and the following to aliases:
'Recaptcha' => CrazyInventor\Lacaptcha\Facades\Lacaptcha::class,
Publish the recaptcha configuration file by running the following command from a shell inside your Laravel's installation directory:
php artisan vendor:publish
This will create the file config/recaptcha.php in your Laravel's installation directory. You can modify this file by entering your sitekey and secret directly to it or adding the keys to your .env file.
Add RECAPTCHA_SECRET and RECAPTCHA_SITEKEY to your .env file:
RECAPTCHA_SECRET=[secret-key]
RECAPTCHA_SITEKEY=[site-key]
Replace [secret-key] and [site-key] with your keys.
{!! Recaptcha::render() !!} to echo out the markup.$rules = [
// ...
'g-recaptcha-response' => 'required|recaptcha',
];
When testing your application you might want to skip the recaptcha part. To do so add these lines at the start of your test:
// prevent validation error on captcha
Recaptcha::shouldReceive('verify')
->once()
->andReturn(true);
// provide hidden input for your 'required' validation
Recaptcha::shouldReceive('render')
->zeroOrMoreTimes()
->andReturn('<input type="hidden" name="g-recaptcha-response" value="1" />');
Unfortunately, mocking does not work for Laravel Dusk. But you can overwrite the validator function very easily by adding the following code to your test.
$app = $this->app;
$app['validator']->extend('recaptcha', function ($attribute, $value) use ($app) {
return true;
});