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:
theme, language).Cons:
Low Effort:
composer require coderflex/laravel-turnstile) + publishing config/views (optional).<x-turnstile-widget />) with configurable attributes (e.g., theme, language), requiring minimal HTML changes.LaravelTurnstile::validate() for manual validation in controllers.TurnstileCheck for Laravel’s built-in validation (e.g., $request->validate(['cf-turnstile-response' => new TurnstileCheck()])).Potential Challenges:
.env (no built-in encryption; rely on Laravel’s default .env protections).cf-turnstile-response field name; customization may require extending the package.Minimal:
Mitigation:
.env rotation strategies for Cloudflare keys.spatie/laravel-recaptcha for older versions?language attribute)? If so, how will we manage these dynamically?<x-turnstile-widget /> component.HttpTests to validate form submissions with Turnstile.Preparation:
.env:
TURNSTILE_SITE_KEY=your_site_key
TURNSTILE_SECRET_KEY=your_secret_key
php artisan vendor:publish --tag="turnstile-config"
php artisan vendor:publish --tag="turnstile-views"
Frontend Integration:
<x-turnstile-widget theme="dark" language="en-US" />
cf-turnstile-response field is included in form submissions.Backend Integration:
use Coderflex\LaravelTurnstile\Rules\TurnstileCheck;
$request->validate([
'cf-turnstile-response' => ['required', new TurnstileCheck()],
]);
use Coderflex\LaravelTurnstile\Facades\LaravelTurnstile;
$response = LaravelTurnstile::validate($request->input('cf-turnstile-response'));
if (!$response['success']) {
return back()->withErrors(['captcha' => 'Invalid CAPTCHA']);
}
Testing:
Rollout:
cf-turnstile-response; customization requires extending the package.How can I help you explore Laravel packages today?