Multi-provider captcha integration for Filament forms, supporting hCaptcha, reCAPTCHA v2, reCAPTCHA v3, and Cloudflare Turnstile.
composer require ddr/filament-captcha
Publish the configuration file (optional):
php artisan vendor:publish --tag="captcha-config"
Add the following environment variables to your .env file based on your chosen provider:
CAPTCHA_DRIVER=hcaptcha
HCAPTCHA_SITEKEY=your-site-key
HCAPTCHA_SECRET=your-secret-key
Get your keys at hCaptcha Dashboard.
CAPTCHA_DRIVER=recaptcha_v2
RECAPTCHA_V2_SITEKEY=your-site-key
RECAPTCHA_V2_SECRET=your-secret-key
Get your keys at Google reCAPTCHA Admin Console.
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).
CAPTCHA_DRIVER=turnstile
TURNSTILE_SITEKEY=your-site-key
TURNSTILE_SECRET=your-secret-key
Get your keys at Cloudflare Turnstile Dashboard.
use Ddr\FilamentCaptcha\Forms\Components\Captcha;
public function form(Form $form): Form
{
return $form
->schema([
// ... other fields
Captcha::make('captcha'),
]);
}
You can override the default driver:
Captcha::make('captcha')->driver('recaptcha_v2')
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)
You can use the captcha validation rule independently:
use Ddr\FilamentCaptcha\Rules\Captcha;
$request->validate([
'captcha' => ['required', new Captcha('hcaptcha')],
]);
The captcha field adapts its behavior based on which credentials are configured:
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"
After publishing views, they will be available in resources/views/vendor/filament-captcha/. You can customize:
resources/views/vendor/filament-captcha/drivers/*.blade.phpresources/views/vendor/filament-captcha/forms/components/captcha.blade.phpLaravel will automatically use your published views instead of the package defaults.
After publishing the config file, you can customize driver settings, verify URLs, and other options in config/captcha.php.
| 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 | โ |
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
The MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?