elvisblanco1993/livewire-v4-recaptcha
Composer 安装命令:
composer require elvisblanco1993/livewire-v4-recaptcha
包简介
Add Google reCAPTCHA (v3, v2, invisible) support to Laravel Livewire v4 components
README 文档
README
A lightweight package that adds Google reCAPTCHA protection to Livewire components using a simple directive and attribute.
This package supports:
- Google reCAPTCHA v3
- Google reCAPTCHA v2
- Google reCAPTCHA v2 Invisible
- Laravel
- Livewire v3 and Livewire v4
Developed and maintained by Code Wize Technologies LLC.
Installation
composer require elvisblanco1993/livewire-v4-recaptcha
Configuration
Read Google's documentation to create your reCAPTCHA keys:
https://developers.google.com/recaptcha/intro
Each version requires its own site key and secret key pair.
Supported Versions
| Version | Documentation | Notes |
|---|---|---|
| v3 (recommended) | https://developers.google.com/recaptcha/docs/v3 | Score-based verification |
| v2 | https://developers.google.com/recaptcha/docs/display | Standard checkbox |
| v2 Invisible | https://developers.google.com/recaptcha/docs/invisible | Use 'size' => 'invisible' |
Laravel Configuration
Add the configuration to config/services.php
reCAPTCHA v3
'google' => [
'recaptcha' => [
'site_key' => env('GOOGLE_RECAPTCHA_SITE_KEY'),
'secret_key' => env('GOOGLE_RECAPTCHA_SECRET_KEY'),
'version' => 'v3',
'score' => 0.5,
],
],
score must be between 0 and 1 and determines the minimum trust threshold.
reCAPTCHA v2
'google' => [
'recaptcha' => [
'site_key' => env('GOOGLE_RECAPTCHA_SITE_KEY'),
'secret_key' => env('GOOGLE_RECAPTCHA_SECRET_KEY'),
'version' => 'v2',
'size' => 'normal',
'theme' => 'light',
],
],
Available options:
size: normal | compact | invisible
theme: light | dark
Usage
Livewire Component
Add the #[ValidatesRecaptcha] attribute to the method that processes the form.
use Livewire\Component;
use ElvisBlanco1993\LivewireRecaptcha\ValidatesRecaptcha;
class ContactForm extends Component
{
public string $gRecaptchaResponse;
#[ValidatesRecaptcha]
public function submit()
{
// This only runs if the captcha passes
}
}
If the $gRecaptchaResponse property is not declared, it will be automatically created.
Advanced Configuration
You can override the secret key or score directly:
#[ValidatesRecaptcha(secretKey: 'mysecretkey', score: 0.9)]
This is useful if you want different captcha strictness per form.
Blade Usage
Add the Livewire Directive
Attach the directive to the form you want protected.
<form wire:submit="submit" wire:recaptcha>
<!-- form fields -->
<button type="submit">
Submit
</button>
</form>
Add the Script Directive
Add the Blade directive once on the page:
@livewireRecaptcha
You can add it:
- in the layout
- or only on pages with forms
Error Handling
When verification fails, a validation error is thrown for:
gRecaptchaResponse
Example:
@if ($errors->has('gRecaptchaResponse'))
<div class="text-red-600">
{{ $errors->first('gRecaptchaResponse') }}
</div>
@endif
The translation key is:
livewire-recaptcha::recaptcha.invalid_response
Overriding Settings in Blade
You can override any configuration directly:
@livewireRecaptcha(
version: 'v2',
siteKey: 'your_site_key',
theme: 'dark',
size: 'compact'
)
How It Works
- The form is submitted.
- The
wire:recaptchadirective intercepts the request. - A reCAPTCHA token is generated client-side.
- The token is validated server-side against Google.
- If validation passes, the Livewire method runs.
If validation fails, the request is rejected.
Compatibility
| Package | Supported |
|---|---|
| Laravel | 10+ |
| Livewire | v3 |
| Livewire | v4 |
Security
Always validate reCAPTCHA server-side, which this package does automatically.
Never trust client responses alone.
License
MIT License
elvisblanco1993/livewire-v4-recaptcha 适用场景与选型建议
elvisblanco1993/livewire-v4-recaptcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 78 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「recaptcha」 「laravel」 「livewire」 「google-recaptcha」 「livewire4」 「Code Wize Technologies」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 elvisblanco1993/livewire-v4-recaptcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elvisblanco1993/livewire-v4-recaptcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 elvisblanco1993/livewire-v4-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.
Livewire starter kit for Lunar e-commerce.
A simple and easy to use Google ReCaptcha v3 package for Laravel
Views for the package MedicOneSystems Livewire Datatables with Bootstrap 4
Livewire component that provides drawers (slide overs) that support multiple children while maintaining state.
统计信息
- 总下载量: 78
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-06