kuttumiah/recaptcha
Composer 安装命令:
composer require kuttumiah/recaptcha
包简介
reCAPTCHA Validator for Laravel 5
README 文档
README
A reCAPTCHA Validator for Laravel 5.
This is a forked version of the reCaptcha package for same functionality but with support for reCaptcha Version 3.
(Looking for a Laravel 4 version? Pull the latest 1.x tag. For Laravel 5.0, pull the latest 2.0 tag.)
For reCaptcha v3 support use
dev-masterfrom this repository.
Installation
Add the following line to the require section of composer.json:
{
"require": {
"kuttumiah/recaptcha": "dev-master",
}
}
or run the command below in terminal
$ composer require "kuttumiah/recaptcha:dev-master"
Setup
-
If you are using Laravel 5.5+ and using package auto-discovery, you can skip this step. For older versions or if you have disabled package auto-discovery continue with this step.
In
/config/app.php, add the following toproviders:Kuttumiah\Recaptcha\RecaptchaServiceProvider::class,
and the following to
aliases:'Recaptcha' => Kuttumiah\Recaptcha\Facades\Recaptcha::class,
-
Run
php artisan vendor:publish --provider="Kuttumiah\Recaptcha\RecaptchaServiceProvider". -
In
/config/recaptcha.php, enter your reCAPTCHA public and private keys.- If you are not using the most recent version of reCAPTCHA, set
versionto 2 or 1. - If you are upgrading to v3 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.
- If you are not using the most recent version of reCAPTCHA, set
-
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.',
Migrating from greggilbert/recaptcha package
-
In
/config/app.php, remove the following fromproviders:Greggilbert\Recaptcha\RecaptchaServiceProvider::class,
and the following from
aliases:'Recaptcha' => Greggilbert\Recaptcha\Facades\Recaptcha::class,
-
Remove the following line from the
requiresection ofcomposer.json:{ "require": { "greggilbert/recaptcha": "dev-master", } } -
Run the command below in terminal
$ composer update
-
Follow the Installation and Setup steps.
Note: If you face any issue error while migrating please check the Troubleshoot section.
Usage
v2 (No Captcha)
- In your form, use
{!! Recaptcha::render() !!}to echo out the markup. - In your validation rules, add the following:
$rules = [ // ... 'g-recaptcha-response' => 'required|recaptcha', ];
v1 (Legacy)
- In your form, use
{!! Recaptcha::render() !!}to echo out the markup. - 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' ]);
Troubleshoot
While migrating from greggilbert/recaptcha package you might end up raising an error like below
> @php artisan package:discover
In ProviderRepository.php line 208:
Class 'Greggilbert\Recaptcha\RecaptchaServiceProvider' not found
Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
To resolve the issue I found a helpful resource on Stack Overflow which can fix this issue. Attaching the solution here for convenience.
Go to your project > bootstrap > cache > config.php file. Remove the provider and aliases from the cached array manually.
Or simply remove the file and generate again by running the command below,
$ php artisan config:cache
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.
kuttumiah/recaptcha 适用场景与选型建议
kuttumiah/recaptcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.57k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「recaptcha」 「captcha」 「laravel」 「laravel5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kuttumiah/recaptcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kuttumiah/recaptcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kuttumiah/recaptcha 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Client library for reCAPTCHA with proxy support, a free service that protects websites from spam and abuse.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
A simple and easy to use Google ReCaptcha v3 package for Laravel
Two Captcha
Laravel 5 Securimage helper
CakePHP Captcha Plugin, Image, Math and Google Recaptcha Support
统计信息
- 总下载量: 2.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-22