crazyinventor/laravel5-recaptcha2
Composer 安装命令:
composer require crazyinventor/laravel5-recaptcha2
包简介
A package to use Google Recaptcha V2 with Laravel 5
README 文档
README
Recaptcha v2 for Laravel 5. Inspired by anhskohbo/no-captcha and greggilbert/recaptcha.
Installation
Run 'composer require crazyinventor/laravel5-recaptcha2' or modify your composer.json:
{
"require": {
"crazyinventor/laravel5-recaptcha2": "1.0.1"
}
}
Configuration
Get your keys for recaptcha from the admin page.
Then register the Service Provider.
Laravel 5.0
In /config/app.php, add the following to providers:
'CrazyInventor\Lacaptcha\LacaptchaServiceProvider',
and the following to aliases:
'Recaptcha' => 'CrazyInventor\Lacaptcha\Facades\Lacaptcha',
Laravel 5.1 and newer
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 config file
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.
.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.
Usage
- In your form, use
{!! Recaptcha::render() !!}to echo out the markup. - To validate your form, add the following rule:
$rules = [ // ... 'g-recaptcha-response' => 'required|recaptcha', ];
Testing
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" />');
Testing with Laravel 5.4 and Dusk
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; });
crazyinventor/laravel5-recaptcha2 适用场景与选型建议
crazyinventor/laravel5-recaptcha2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 804 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 crazyinventor/laravel5-recaptcha2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 crazyinventor/laravel5-recaptcha2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 804
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-25