ibehbudov / laravel-google-captcha
用于Laravel验证的Google Captcha规则
dev-master
2022-08-24 07:36 UTC
Requires
- guzzlehttp/guzzle: 7.4.*
- illuminate/contracts: 9.*
- illuminate/http: 9.*
- illuminate/support: 9.*
- psr/http-message: 1.0.*
This package is auto-updated.
Last update: 2024-09-24 12:08:53 UTC
README
## Laravel的Google Captcha
安装
composer require ibehbudov/laravel-google-captcha
发布供应商文件
php artisan vendor:publish --tag=google-captcha
密钥
打开 config/google-captcha.php
文件并编辑
return [ 'secret_key' => 'google_secret_key' ];
使用方法
在控制器内部
$request->validate([ 'g-recaptcha-response' => new GoogleCaptchaRule() ]);
在规则内部
public function rules() { return [ 'g-recaptcha-response' => new GoogleCaptchaRule() ]; }
在您想要的地方
$googleCaptcha = app(GoogleCaptcha::class); $googleCaptcha->validate($request->post('g-recaptcha-response')); if($googleCaptcha->fail()) { return $googleCaptcha->getErrorMessage(); } else { // code goes here }