coderflex/laravel-turnstile
Add Cloudflare Turnstile CAPTCHA to Laravel with minimal setup. Includes config publishing, env-based site/secret keys, validation integration, and customizable/translatable error messages for protecting forms and endpoints from bots.
Pros:
LaravelTurnstile) and custom validation rule (TurnstileCheck) align with Laravel’s validation ecosystem, reducing friction for developers..env-based key management aligns with Laravel’s security best practices.TurnstileCheck rule) for form-level errors.LaravelTurnstile::validate()) for programmatic checks.
This reduces edge cases and improves developer experience.Cons:
composer require + php artisan vendor:publish for config/views.<x-turnstile-widget />) with configurable props (theme, language, etc.).$response = LaravelTurnstile::validate($request->input('cf-turnstile-response')).'cf-turnstile-response' => [new TurnstileCheck()].cf-turnstile-response field is included.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| API Changes | Cloudflare may modify Turnstile’s API (e.g., response format, endpoints). | Use the facade as an abstraction layer; monitor Cloudflare’s changelog. |
| Laravel Version | Package drops support for Laravel 10/PHP 8.1. | Ensure project uses Laravel 11/12+; if not, evaluate custom integration. |
| Rate Limiting | Cloudflare may throttle Turnstile verification requests. | Implement exponential backoff in the facade or cache responses (e.g., Redis). |
| False Positives | Turnstile may incorrectly flag legitimate users. | Use Cloudflare’s testing mode during development; monitor false-positive rates. |
| CSRF/Token Issues | Turnstile responses may conflict with Laravel’s CSRF protection. | Ensure cf-turnstile-response is included in the form’s CSRF meta tag or hidden field. |
| Performance | Additional HTTP call to Cloudflare may slow down form submission. | Cache validation responses (e.g., Redis) for high-traffic forms. |
| Localization | Widget language/theme may not render correctly in all regions. | Test with target locales; use Turnstile’s language prop for dynamic adaptation. |
<x-turnstile-widget /> component.cf-turnstile-response field is included in the form submission.| Step | Action | Effort | Dependencies |
|---|---|---|---|
| 1. Prep Environment | Ensure Laravel 11/12+ and PHP 8.2+. Update composer.json if needed. |
Low | DevOps |
| 2. Install Package | composer require coderflex/laravel-turnstile |
Low | Composer |
| 3. Configure Keys | Add TURNSTILE_SITE_KEY and TURNSTILE_SECRET_KEY to .env. |
Low | Cloudflare Dashboard |
| 4. Publish Config | php artisan vendor:publish --tag="turnstile-config" |
Low | Laravel CLI |
| 5. Publish Views (Optional) | php artisan vendor:publish --tag="turnstile-views" (if customizing widget appearance). |
Low | Laravel CLI |
| 6. Integrate Widget | Replace existing CAPTCHA with <x-turnstile-widget /> in target forms. |
Medium | Frontend Team |
| 7. Backend Validation | Add LaravelTurnstile::validate() or TurnstileCheck rule to form handlers. |
Medium | Backend Team |
| 8. Test Locally | Use Cloudflare’s dummy keys | Low | QA |
| 9. Deploy to Staging | Test with real traffic (or staging users) to monitor false positives. | Medium | QA/DevOps |
| 10. Monitor & Optimize | Track failure rates; adjust widget settings (e.g., ` |
How can I help you explore Laravel packages today?