ddr/filament-captcha
Composer 安装命令:
composer require ddr/filament-captcha
包简介
Multi-provider captcha integration for Filament forms (hCaptcha, reCAPTCHA v2/v3, Turnstile)
README 文档
README
Multi-provider captcha integration for Filament forms, supporting hCaptcha, reCAPTCHA v2, reCAPTCHA v3, and Cloudflare Turnstile.
Features
- 🔒 Multiple captcha providers (hCaptcha, reCAPTCHA v2, reCAPTCHA v3, Turnstile)
- 🎨 Seamless integration with Filament forms
- ⚙️ Driver-based architecture for easy extension
- 🧪 Comprehensive test coverage
- 📦 Compatible with Filament v3, v4 and v5
- 🔧 Development mode support
Requirements
- PHP ^8.2
- Laravel 11, 12 or 13
- Filament 3, 4 or 5
Installation
composer require ddr/filament-captcha
Publish the configuration file (optional):
php artisan vendor:publish --tag="captcha-config"
Configuration
Add the following environment variables to your .env file based on your chosen provider:
hCaptcha
CAPTCHA_DRIVER=hcaptcha HCAPTCHA_SITEKEY=your-site-key HCAPTCHA_SECRET=your-secret-key
Get your keys at hCaptcha Dashboard.
Google reCAPTCHA v2
CAPTCHA_DRIVER=recaptcha_v2 RECAPTCHA_V2_SITEKEY=your-site-key RECAPTCHA_V2_SECRET=your-secret-key
Get your keys at Google reCAPTCHA Admin Console.
Google reCAPTCHA v3
CAPTCHA_DRIVER=recaptcha_v3 RECAPTCHA_V3_SITEKEY=your-site-key RECAPTCHA_V3_SECRET=your-secret-key RECAPTCHA_V3_SCORE=0.5
Get your keys at Google reCAPTCHA Admin Console.
The RECAPTCHA_V3_SCORE determines the minimum score required to pass validation (0.0 - 1.0, default: 0.5).
Cloudflare Turnstile
CAPTCHA_DRIVER=turnstile TURNSTILE_SITEKEY=your-site-key TURNSTILE_SECRET=your-secret-key
Get your keys at Cloudflare Turnstile Dashboard.
Usage
In Filament Forms
use Ddr\FilamentCaptcha\Forms\Components\Captcha; public function form(Form $form): Form { return $form ->schema([ // ... other fields Captcha::make('captcha'), ]); }
Specifying a Driver
You can override the default driver:
Captcha::make('captcha')->driver('recaptcha_v2')
Custom Login Page
Create a custom login page extending Filament's base login:
<?php namespace App\Filament\Pages\Auth; use Ddr\FilamentCaptcha\Forms\Components\Captcha; use Filament\Auth\Pages\Login as BaseLogin; use Filament\Schemas\Schema; class Login extends BaseLogin { public function form(Schema $schema): Schema { return $schema ->components([ $this->getEmailFormComponent(), $this->getPasswordFormComponent(), $this->getRememberFormComponent(), Captcha::make('captcha')->hiddenLabel(), ]); } }
Then register it in your AdminPanelProvider:
->login(\App\Filament\Pages\Auth\Login::class)
Validation Rule
You can use the captcha validation rule independently:
use Ddr\FilamentCaptcha\Rules\Captcha; $request->validate([ 'captcha' => ['required', new Captcha('hcaptcha')], ]);
Development Mode
The captcha field adapts its behavior based on which credentials are configured:
- No site key configured: the field is completely hidden and validation is skipped, allowing forms to work without any captcha setup.
- Site key configured, no secret key: the widget is displayed but server-side verification is skipped. Useful for testing the UI locally.
- Both keys configured: full captcha flow with server-side verification (production).
Customization
Publishing Assets
You can publish and customize the package's configuration, views, and translations:
# Publish configuration file php artisan vendor:publish --tag="captcha-config" # Publish views php artisan vendor:publish --tag="filament-captcha-views" # Publish translations php artisan vendor:publish --tag="filament-captcha-translations"
Customizing Views
After publishing views, they will be available in resources/views/vendor/filament-captcha/. You can customize:
- Driver-specific widgets:
resources/views/vendor/filament-captcha/drivers/*.blade.php - Main component:
resources/views/vendor/filament-captcha/forms/components/captcha.blade.php
Laravel will automatically use your published views instead of the package defaults.
Customizing Configuration
After publishing the config file, you can customize driver settings, verify URLs, and other options in config/captcha.php.
Provider Comparison
| Feature | hCaptcha | reCAPTCHA v2 | reCAPTCHA v3 | Turnstile |
|---|---|---|---|---|
| Privacy-focused | ✅ | ❌ | ❌ | ✅ |
| User interaction | ✅ Checkbox | ✅ Checkbox | ❌ Invisible | ⚡ Smart |
| Score-based | ❌ | ❌ | ✅ | ✅ |
| Free tier | ✅ Unlimited | ✅ 1M/month | ✅ 1M/month | ✅ Unlimited |
| GDPR compliant | ✅ | ⚠️ Requires config | ⚠️ Requires config | ✅ |
Testing
composer test # Run tests composer lint # Check code style composer lint:fix # Fix code style composer analyse # Run static analysis composer check # Run all checks
License
The MIT License (MIT). Please see License File for more information.
ddr/filament-captcha 适用场景与选型建议
ddr/filament-captcha 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.89k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「recaptcha」 「captcha」 「laravel」 「filament」 「hcaptcha」 「turnstile」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ddr/filament-captcha 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ddr/filament-captcha 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ddr/filament-captcha 相关的其它包
同方向 / 同关键字的高下载量 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.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-23