newscoop/recaptcha-bundle
A Symfony bundle that adds Google reCAPTCHA support to Newscoop, helping protect forms and user-facing pages from spam and automated abuse with configurable challenge verification during submissions.
First, calibrate expectations: this is a Symfony bundle, not a Laravel package. newscoop/recaptcha-bundle is a fork of Exceliance's EWZRecaptchaBundle, last tagged in 2014, targeting Symfony 2.x and the reCAPTCHA v1/early-v2 era. It has no Laravel service provider, no config/recaptcha.php, and no facade. In a Laravel codebase you will not composer require this and get a working captcha; you will either (a) use it inside a legacy Symfony app, or (b) mine it for the pattern and reimplement it idiomatically in Laravel.
Where to look first, in order:
README.md — the canonical usage snippet (form type + Twig widget).DependencyInjection/Configuration.php — the real config surface (public_key, private_key, enabled, locale, secure, theme, type, size).Form/Type/EWZRecaptchaType.php — the field definition and how it reads config.Resources/views/Form/*.twig — the widget markup and the g-recaptcha JS include.Minimal Symfony usage looks like:
# config.yml
ewz_recaptcha:
public_key: '%recaptcha_public%'
private_key: '%recaptcha_private%'
enabled: true
$builder->add('recaptcha', EWZRecaptchaType::class);
For a Laravel developer, the realistic first use case is porting that contract into a custom validation rule plus a Blade partial — not installing the bundle.
Symfony form-type pattern (the bundle's native path). Add the field to a form, render the widget through the bundle's form theme, and rely on server-side verification on submit. This is the pattern the package was built for.
The Laravel equivalent you'll actually ship. Reproduce the same three moving parts — site key in the view, response token in the POST, secret-key verification server-side:
// AppServiceProvider::boot()
Validator::extend('recaptcha', function ($attribute, $value) {
return Http::asForm()
->post('https://www.google.com/recaptcha/api/siteverify', [
'secret' => config('services.recaptcha.secret'),
'response' => $value,
'remoteip' => request()->ip(),
])
->json('success') ?? false;
});
<div class="g-recaptcha" data-sitekey="{{ config('services.recaptcha.sitekey') }}"></div>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
Then 'g-recaptcha-response' => 'required|recaptcha' in the FormRequest.
Config-driven enable/disable. Mirror the bundle's enabled flag with config('services.recaptcha.enabled') so tests and local dev bypass the network call. This is the single most valuable idea to carry over.
Integration tips. Keep the secret in config/services.php + .env; never echo it. Wrap the verify call in a small service so you can fake it in tests (Http::fake()). If you're genuinely inside Symfony, register the bundle in AppKernel, import the routing-free config, and pull the form theme into your Twig config.
Recaptcha facade. Treat it as reference source, not a dependency.example.com silently fails on localhost; use Google's documented test keys for local work.g-recaptcha-response or a success: false from siteverify is the only thing that matters. Always check success and consider score/action if you migrate to v3.api.js; under a strict Content-Security-Policy you must allow https://www.google.com in script-src and often frame-src. This trips people up more than the captcha logic itself.api.js)? Is g-recaptcha-response present in the POST? What does the raw siteverify JSON say — error-codes usually names the problem (invalid-input-secret, timeout-or-duplicate)?EWZRecaptchaType to swap in a v2/v3-compatible renderer. Both are cleaner than patching the vendored bundle.How can I help you explore Laravel packages today?