Weave Code
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

No Captcha Laravel Package

anhskohbo/no-captcha

Laravel package to integrate Google reCAPTCHA (No CAPTCHA) in your forms. Includes config via .env, Blade helpers to render JS and display widgets, supports language and custom attributes, and works with Laravel 5+ (auto-discovery on 5.5+).

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Alignment: Perfectly aligns with Laravel’s ecosystem, leveraging service providers, facades, and Blade templating for minimal integration effort. Auto-discovery (Laravel 5.5+) reduces boilerplate to a single .env configuration.
  • Validation Integration: Seamlessly extends Laravel’s validator with a captcha rule, eliminating custom validation logic and reducing form-handling complexity.
  • Blade-Centric Design: Blade helpers (renderJs(), display(), displaySubmit()) are idiomatic for Laravel apps, enabling quick UI integration without frontend framework constraints.
  • Invisible reCAPTCHA Support: Addresses UX pain points (e.g., login forms) by offering a submit-button-triggered flow, critical for high-conversion paths.
  • Modularity: Standalone PHP usage (via NoCaptcha class) allows integration into non-Laravel PHP stacks, though Laravel-specific features (e.g., validation) are lost.

Integration Feasibility

  • Low-Coupling Design: Minimal dependencies (Guzzle for HTTP requests) and no database requirements, making it easy to add/remove.
  • Backward Compatibility: Supports Laravel 5.1–12, ensuring viability for legacy and modern stacks. Lumen support adds flexibility for API-heavy projects.
  • Configuration Simplicity: Single .env entry (NOCAPTCHA_SECRET, NOCAPTCHA_SITEKEY) and optional Blade snippets for JS rendering.
  • Google reCAPTCHA v2 Dependency: Locks into Google’s ecosystem; migrating to v3 would require reimplementation (risk: breaking changes).
  • Validation Hardcoding: Relies on g-recaptcha-response field name; custom names require middleware workarounds.

Technical Risk

  • JavaScript Dependency: External JS library introduces latency and potential CORS/blocking issues if not loaded correctly (e.g., ad blockers, strict CSP policies).
  • Testing Complexity: Mocking the facade in tests requires stubbing both verifyResponse() and display() methods, adding maintenance overhead.
  • Secret Key Management: No built-in rotation or audit logging; compliance-heavy environments may need custom solutions.
  • Invisible reCAPTCHA Edge Cases: Form ID mismatches or missing JS callbacks can cause silent failures, requiring robust frontend error handling.
  • Validation Coupling: Hardcoded field name may conflict with existing form structures or custom validation pipelines.
  • Rate Limiting: Google’s reCAPTCHA has quotas, which could impact high-traffic forms without monitoring.

Key Questions

  1. Laravel Version: Is the project on Laravel 5.5+ (auto-discovery) or older (manual setup)? Does it need Lumen support?
  2. CAPTCHA Version: Should we use v2 (visible/invisible) or explore v3 (risk: requires reimplementation) for risk-based scoring?
  3. Validation Customization: Are custom field names or validation messages needed beyond the package’s defaults?
  4. Testing Strategy: How will we mock reCAPTCHA in CI/CD pipelines (e.g., GitHub Actions) where real responses aren’t feasible?
  5. Compliance: Are there requirements for logging CAPTCHA attempts or rotating secret keys programmatically?
  6. Performance: Will reCAPTCHA JS load times impact critical user journeys (e.g., checkout)? Consider lazy-loading or invisible reCAPTCHA.
  7. Fallbacks: Should we implement a fallback (e.g., hCaptcha) if Google’s service is unavailable?
  8. Multi-region Deployment: Are there regional restrictions (e.g., GDPR) that require reCAPTCHA configuration per environment?
  9. Form Framework Compatibility: If using frontend frameworks (e.g., Vue, React), how will Blade helpers integrate (e.g., via Inertia.js or custom components)?
  10. Error Handling: How will we surface reCAPTCHA errors to users (e.g., API responses, frontend toast notifications)?

Integration Approach

Stack Fit

  • Primary: Laravel 5.5–12 (auto-discovery), Lumen, or standalone PHP apps needing reCAPTCHA v2.
    • Laravel: Ideal for Blade-based apps; validation and JS integration are seamless.
    • Lumen: Supported but requires manual service provider registration.
    • Standalone PHP: Works but loses Laravel-specific features (e.g., validation).
  • Secondary: Compatible with any frontend (Blade, Vue, React) but requires manual JS integration for non-Blade templates.
    • Vue/React: Use Inertia.js or custom components to render Blade helpers or call the NoCaptcha class directly.
    • APIs: For headless apps, use the standalone NoCaptcha class to verify responses via API endpoints.
  • Validation: Native integration with Laravel’s validator; standalone use requires manual response verification via verifyResponse().
  • Testing: Mocking support for unit/feature tests; HTTP tests require g-recaptcha-response in request payloads.

Migration Path

  1. Assessment Phase:
    • Audit existing CAPTCHA implementations for compatibility (e.g., custom field names, validation logic).
    • Verify Laravel version and update if needed (e.g., to 5.5+ for auto-discovery).
    • Document high-traffic forms (e.g., checkout, contact) where reCAPTCHA will be prioritized.
  2. Setup:
    • Install package: composer require anhskohbo/no-captcha.
    • Configure .env with NOCAPTCHA_SECRET and NOCAPTCHA_SITEKEY (obtain from Google reCAPTCHA Admin).
    • For Laravel <5.5: Register the service provider and facade in config/app.php.
    • Publish config (if customization needed): php artisan vendor:publish --provider="Anhskohbo\NoCaptcha\NoCaptchaServiceProvider".
  3. Integration:
    • Blade Templates: Add {{ NoCaptcha::renderJs() }} to layouts/partials (e.g., _head.blade.php).
    • Forms:
      • Visible reCAPTCHA: {{ NoCaptcha::display() }} or {{ NoCaptcha::display(['data-theme' => 'dark']) }}.
      • Invisible reCAPTCHA: {{ NoCaptcha::displaySubmit('form-id', 'Submit', ['data-theme' => 'dark']) }}.
    • Validation: Add 'g-recaptcha-response' => 'required|captcha' to form rules.
    • Custom Messages: Extend validation.php for localized error messages.
  4. Testing:
    • Mock facade in unit tests:
      NoCaptcha::shouldReceive('verifyResponse')->andReturn(true);
      NoCaptcha::shouldReceive('display')->andReturn('<input type="hidden" name="g-recaptcha-response" value="1" />');
      
    • HTTP tests: Include g-recaptcha-response in POST data:
      $this->post('/register', ['g-recaptcha-response' => '1', 'email' => 'test@example.com']);
      
  5. Optimization:
    • Lazy-load reCAPTCHA JS for non-critical forms to reduce initial load time.
    • Implement invisible reCAPTCHA for high-conversion forms (e.g., checkout).
    • Monitor Google’s quota limits and implement fallback mechanisms if needed.

Compatibility

  • Laravel Versions: 5.1–12 (tested); auto-discovery for 5.5+.
  • PHP Versions: Compatible with Laravel’s supported PHP versions (e.g., 8.0+ for Laravel 10/11/12).
  • Frontend Frameworks: Works with Blade natively; requires adapters for Vue/React (e.g., Inertia.js).
  • Alternatives: No built-in support for hCaptcha or other providers; would require custom implementation.

Sequencing

  1. Phase 1 (1–2 days): Setup and basic integration (.env, Blade helpers, validation).
  2. Phase 2 (1 day): Test mocking and CI/CD pipeline updates.
  3. Phase 3 (1–3 days): Roll out to high-priority forms (e.g., contact, registration).
  4. Phase 4 (Ongoing): Monitor performance, quotas, and user feedback; optimize JS loading and error handling.

Operational Impact

Maintenance

  • Low Effort: Minimal maintenance required; updates align with Laravel’s release cycle.
  • Dependency Management: Monitor Google reCAPTCHA’s API changes (e.g., deprecations) and package updates (e.g., Guzzle compatibility).
  • Secret Rotation: No built-in rotation; implement custom logic if required (e.g., via Laravel’s env rotation tools or a cron job).
  • Logging: No native logging; extend the package or wrap verifyResponse() to log attempts for compliance/audit purposes.

Support

  • Troubleshooting: Common issues
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport