Pros:
VerifyCaptcha), reducing boilerplate in controllers.captcha.validated) for extensibility, enabling custom logic post-validation (e.g., logging, analytics)..env configuration for site keys, thresholds (e.g., reCAPTCHA score), and provider toggling, adhering to Laravel’s 12-factor principles.Cons:
Validator facade (e.g., Rule::captcha()), enabling fluent validation rules.@captcha Blade directives for frontend integration, reducing coupling between backend logic and views.Captcha::generateToken(), compatible with Laravel Sanctum/Passport for token-based auth.guzzlehttp/guzzle for API calls to CAPTCHA providers (already bundled in Laravel).HCaptchaService, RecaptchaService) simplify unit testing.CaptchaFake for seamless testing in Laravel’s testing framework..env files could leak secret keys. Package includes basic validation but relies on developer discipline.0.3–0.9 range)? Will thresholds vary by form criticality?CaptchaFake)? Will staging use real or fake tokens?required|captcha) with martian/laracaptcha.VerifyCaptcha middleware for route-level protection (e.g., Route::middleware(['captcha'])->group(...)).captcha.validated for analytics or logging (e.g., Event::listen(CaptchaValidated::class, fn($event) => Log::info($event->data))).@captcha directives for rendering widgets (e.g., @captcha('hcaptcha')).fetch or form submissions.axios.post('/api/contact', { ... }, { headers: { 'X-Captcha-Token': token } })).Authorization: Bearer ... + X-Captcha-Token header)..env:
CAPTCHA_PROVIDER=recaptcha_v3
RECAPTCHA_SITE_KEY=...
RECAPTCHA_SECRET_KEY=...
RECAPTCHA_SCORE_THRESHOLD=0.5
composer require martian/laracaptcha
php artisan vendor:publish --provider="Martian\Laracaptcha\LaracaptchaServiceProvider"
config/captcha.php for provider-specific settings (e.g., hCAPTCHA’s size or theme).$validated = $request->validate([
'captcha' => 'required|captcha',
]);
$token = Captcha::generateToken('recaptcha_v3');
return response()->json(['token' => $token]);
@captcha('hcaptcha', ['size' => 'invisible'])
CaptchaFake in unit tests:
use Martian\Laracaptcha\Facades\Captcha;
Captcha::shouldReceive('verify')->andReturn(true);
composer.json constraints). Test thoroughly if using 10.x/11.x.grecaptcha.execute() JS snippet.hcaptcha.render() JS snippet.How can I help you explore Laravel packages today?