kamilwojtalak / laravel-recaptcha-v3
Laravel reCaptcha v3 实现。
dev-master
2024-05-21 17:44 UTC
This package is auto-updated.
Last update: 2024-09-21 18:20:37 UTC
README
安装
composer require kamilwojtalak/laravel-recaptcha-v3:dev-master
首先获取您的密钥!
首先,您需要在 这里 创建自己的API密钥
按照说明操作,过程结束时,您将找到网站密钥和密钥。请妥善保管……您很快就会用到!
如何使用
将这些环境变量添加到您的 .env 文件中
RECAPTCHA_SITE_KEY='xxxxxxxxxxxxxxxxx'
RECAPTCHA_SECRET_KEY='xxxxxxxxxxxxxxxxx'
然后发布配置文件
php artisan vendor:publish --provider="Wojtalak\LaravelRecaptchaV3\Providers\LaravelRecaptchaV3ServiceProvider"
好的,现在……当您想在 .blade.php(您的表单所在位置)中使用 recaptcha 时,您必须执行以下操作
@push('head_scripts')
@reCaptchaHead()
@endpush
@push('footer_scripts')
@reCaptchaFooter('demo-form')
@endpush
请注意,您必须相应地定义您的 @stacks。
然后,当您定义表单时,您必须
<form action="<your url>" method="<your method>" id="demo-form">
... <your code> ...
<button class="g-recaptcha" data-sitekey="{{ config('recaptcha.api_site_key') }}"
data-callback="onSubmitRecaptcha" data-action="submit">
{{ __('Submit') }}
</button>
</form>
请注意,您需要在两个地方提供您表单的 ID,1) @reCaptchaFooter('demo-form'),2) id="demo-form"
在您的验证请求内部
use Wojtalak\LaravelRecaptchaV3\Rules;
...
public function rules(): array
{
return [
... <the rest of the request rules> ...
'g-recaptcha-response' => ['required' , new Rules\Recaptcha]
];
}
祝您玩得愉快!😎