Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Recaptcha Bundle Laravel Package

pierre-vassoilles/recaptcha-bundle

Symfony bundle that integrates Google reCAPTCHA into forms and controllers, with configuration, validation, and Twig helpers to help protect applications from spam and automated abuse with minimal setup.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Confirm the package actually targets Laravel. RecaptchaBundle naming suggests a Symfony-style bundle; check composer.json for laravel/illuminate support and whether Laravel package auto-discovery is present. If it is Symfony-only, use it through a small Laravel adapter/service rather than assuming it auto-wires.
  • Look first at: README, composer.json, package config files (config/recaptcha.php, DependencyInjection/*, or bundle config), the verifier/client class, and any validation rule or middleware shipped by the package.
  • Configure the minimum environment values before wiring forms: site key, secret key, reCAPTCHA version/mode (v2 checkbox, v2 invisible, v3 score), and expected score/action if using v3.
  • First use case: protect a low-risk form such as contact or login. Render the widget with the public site key in Blade, then validate the submitted g-recaptcha-response server-side before the controller action runs.
  • For a first Laravel integration, bind the package verifier behind a small application-level interface and call it from a Form Request rule or middleware. This keeps controllers clean and makes testing replaceable.
  • Treat 0.9.0 as the first stable baseline, not a mature 1.0: verify public APIs against source before standardizing usage across the app.

Implementation Patterns

  • Form Request validation rule: Wrap the package verifier in a custom rule, e.g. RecaptchaValid, and attach it to forms that need protection. Validate token presence, Google success flag, expected action, score threshold, and optionally hostname.
  • Middleware for route groups: Use middleware for broad protection on routes like login, register, password reset, and public POST endpoints. Keep the middleware configurable so sensitive or API routes can opt out.
  • Service wrapper: Do not call the bundle/client directly from many controllers. Define an application service such as RecaptchaVerifier with a verify(string $token, ?string $action, ?string $ip): Result method, then bind the package implementation in a service provider.
  • Blade component/partial: Create one reusable widget partial or component that reads the configured site key and reCAPTCHA mode. For v3, render/execute the script near the form submit handler; for v2, render the checkbox/invisible widget explicitly.
  • Config-driven policies: Put score thresholds, expected actions, allowed hostnames, and bypass behavior in config. Use different actions per form, e.g. contact, login, register, so v3 assessments are interpretable.
  • Testing workflow: Bind a fake verifier in tests so no network call is made. Assert that invalid/missing tokens fail validation and that valid fakes pass. Keep one optional integration test against Google test keys for smoke coverage.
  • Local/CI behavior: Provide an explicit bypass switch for local and testing, but make it impossible to enable silently in production. Prefer a fake verifier over disabling validation logic entirely.
  • Error handling: Normalize Google failure reasons into application-level validation messages. Log the raw error codes and score/action data for debugging, but do not expose secret-key internals to users.
  • Integration tip: If the package is Symfony-oriented, keep the adapter thin: one Laravel service provider, one config file, one validation rule/middleware. Avoid spreading bundle-specific classes through domain code.

Gotchas and Tips

  • Package type mismatch: “Bundle” strongly implies Symfony. Verify Laravel compatibility before adopting; if absent, this is not a drop-in Laravel package.
  • Secret key exposure: Only the site key belongs in Blade/JS. The secret key must stay server-side and must never appear in compiled assets or logs.
  • Token lifetime and reuse: reCAPTCHA tokens are short-lived and single-use. Validate immediately on submit, do not cache tokens, and do not retry verification with the same token.
  • v2 vs v3 behavior: v3 returns a score, not a simple pass/fail. You must choose action names and thresholds deliberately; a global low threshold weakens protection.
  • Expected action/hostname checks: For v3, validate action and consider hostname; otherwise tokens from other forms or environments may be accepted.
  • Config caching: After changing keys, thresholds, or package config, run php artisan config:clear / config:cache as appropriate. Environment changes will not take effect if config is cached incorrectly.
  • CSP and script loading: reCAPTCHA loads external Google scripts. Check Content Security Policy rules for www.google.com, www.gstatic.com, and related reCAPTCHA domains.
  • Local development: Use Google’s documented test keys where appropriate, but do not let test-key configuration leak into staging/production. Confirm behavior on localhost and behind proxies.
  • Error-code debugging: Log Google’s error-codes such as invalid input response, timeout-or-duplicate, and bad request. Distinguish user error from misconfiguration.
  • Proxy/IP handling: If sending remote IP, ensure trusted proxy configuration is correct in Laravel; otherwise verification metadata may be misleading.
  • Semver caution: 0.9.0 is the first stable release. Pin the version, review source diffs before upgrades, and keep the adapter layer small so future package changes do not ripple through the app.
  • Extension points to preserve: Custom HTTP client/timeouts, verifier interface binding, config repository, validation messages, and test fake. These are the seams that make the package replaceable if it proves Symfony-first or too limited for Laravel day-to-day use.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo