composer require l3aro/filament-turnstile
php artisan vendor:publish --tag="filament-turnstile-config"
.env:
TURNSTILE_SITE_KEY=your_site_key
TURNSTILE_SECRET_KEY=your_secret_key
Login page):
use l3aro\FilamentTurnstile\Forms\Turnstile;
Turnstile::make('captcha')
->theme(TurnstileTheme::Auto)
->size(TurnstileSize::Normal)
Protect a Filament login form from bots:
// In your custom Login page class
protected function getForms(): array {
return [
'form' => $this->form()
->schema([
// ... other fields
Turnstile::make('captcha'),
]),
];
}
Form Integration:
Turnstile field to any Filament form (e.g., Login, Registration, or custom forms).theme(), size(), language()).Validation:
Reset Logic:
reset-captcha event after failed submissions (e.g., in onValidationError):
protected function onValidationError(ValidationException $exception) {
$this->dispatch(FilamentTurnstileFacade::getResetEventName());
}
Turnstile::make('captcha')
->theme($this->isDarkMode() ? TurnstileTheme::Dark : TurnstileTheme::Light)
Turnstile::make('captcha')
->language(app()->getLocale())
Turnstile::make('captcha')
->visible(fn () => $this->isHighRiskForm())
Login page in your PanelProvider:
->login(\App\Filament\Pages\Auth\CustomLogin::class)
TURNSTILE_SITE_KEY=0x4AAAAAAAAAAAAAAAAAAAAAGGeSlV
TURNSTILE_SECRET_KEY=0x4AAAAAAAAAAAAAAAAAAAAAGGeSlV
Key Mismatch:
TURNSTILE_SITE_KEY and TURNSTILE_SECRET_KEY match your Cloudflare dashboard.403 Forbidden errors (invalid secret key).Event Naming Collisions:
reset-captcha as a custom JavaScript event name elsewhere in your app.'reset_event' => 'custom-reset-event',
Blade Template Issues:
BackedEnum values are cast to strings (fixed in v1.0.7).Livewire Reset Timing:
onValidationError runs after the form re-renders.updated():
public function updated($property) {
if ($this->wasSuccessful && $this->hasErrors()) {
$this->dispatch(FilamentTurnstileFacade::getResetEventName());
}
}
.env to see detailed logs:
TURNSTILE_DEBUG=true
/cdn-cgi/turnstile/v0/captcha endpoint for failed submissions.Custom Validation: Override the default validation rule:
Turnstile::make('captcha')
->rules(['custom.turnstile' => 'required|valid_turnstile'])
Register the rule in a service provider:
Validator::extend('valid_turnstile', function ($attribute, $value, $parameters) {
return TurnstileValidator::validate($value);
});
Theme/Size Enums: Extend existing enums for custom options:
class CustomTurnstileSize extends TurnstileSize {
public const Compact = 'compact';
}
Event Listeners: Listen for Turnstile events globally:
Event::listen(FilamentTurnstileFacade::getResetEventName(), function () {
Log::info('Turnstile reset triggered');
});
How can I help you explore Laravel packages today?