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

Laravel Cookie Consent Laravel Package

spatie/laravel-cookie-consent

Add a simple, customizable cookie consent banner to Laravel. Shows on first visit, stores consent, then stays hidden. No “decline” option, no tracker blocking, and no consent categories—use other tools if you need advanced compliance features.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:
    • Lightweight, modular design with clear separation of concerns (config, views, middleware).
    • Leverages Laravel’s built-in features (e.g., middleware, blade views, translations) for seamless integration.
    • Supports modern Laravel versions (9–13) and PHP 8.0+, aligning with current stack trends.
    • TailwindCSS-based styling (default) reduces frontend overhead and ensures consistency.
    • Configurable via .env and published config files, enabling environment-specific customization.
  • Cons:
    • Limited granularity: Does not natively support multi-category consent (e.g., "Necessary" vs. "Analytics") or decline options, which may require custom extensions.
    • No built-in tracker blocking: Requires manual implementation (e.g., middleware to block scripts until consent).
    • Cookie-only persistence: Relies solely on HTTP cookies, which may not suffice for SPAs or headless apps (though middleware can mitigate this).

Integration Feasibility

  • High:
    • Zero-config installation (composer require) with auto-registration.
    • Two primary integration paths:
      1. Blade inclusion (@include('cookie-consent::index')) for explicit control.
      2. Middleware (CookieConsentMiddleware) for global enforcement (Laravel 9–13 compatible).
    • Minimal dependencies (only Laravel core), reducing conflict risk.
    • Supports both monolithic and modular Laravel architectures (e.g., Filament plugins via marcogermani87/filament-cookie-consent).

Technical Risk

  • Low to Medium:
    • Compatibility: Tested across Laravel 9–13 and PHP 8.0+, but edge cases (e.g., custom session drivers) may require validation.
    • Customization Gaps: Extending functionality (e.g., decline buttons, consent categories) requires custom views/middleware, adding minor dev effort.
    • Legal Compliance: Not a substitute for legal review—package clarifies it does not provide legal advice (see README).
    • Performance: Minimal impact (cookie check + view render), but middleware adds a global hook (benchmark if critical).

Key Questions

  1. Regulatory Requirements:
    • Does the project require multi-category consent (e.g., GDPR’s "Necessary," "Preferences," "Statistics") or decline options? If yes, custom extensions or alternative packages (e.g., whitecube/laravel-cookie-consent) may be needed.
    • Are third-party trackers (e.g., Google Analytics) used? If so, how will consent be enforced (e.g., middleware to block scripts until consent)?
  2. User Experience:
    • Should the banner be fixed/floating (default) or in-page? CSS customization is supported but may need adjustments for complex layouts.
    • Are localized translations required beyond English? The package supports publishing lang files for customization.
  3. Technical Constraints:
    • Is the app headless or SPA-based? If so, cookie-based persistence may need supplementation (e.g., localStorage sync via middleware).
    • Are there custom session drivers (e.g., Redis)? The package inherits Laravel’s session config, so SESSION_DOMAIN must be set in .env.
  4. Maintenance:
    • Who will handle legal updates (e.g., new consent categories)? The package is MIT-licensed and community-driven.
    • Is A/B testing needed for consent banners? Custom views allow experimentation, but analytics would require additional instrumentation.

Integration Approach

Stack Fit

  • Laravel-Centric: Optimized for Laravel’s ecosystem (middleware, blade, translations, config).
  • Frontend Agnostic:
    • Works with Blade, Livewire, or Inertia.js (via middleware or manual inclusion).
    • TailwindCSS default reduces styling friction but can be replaced with custom CSS.
  • Backend Compatibility:
    • Supports PHP 8.0+ and Laravel 9–13, with backward compatibility for older versions.
    • No database requirements; uses HTTP cookies for persistence.

Migration Path

  1. Assessment Phase:
    • Audit current cookie usage (e.g., analytics, ads) to define consent categories.
    • Verify legal requirements (e.g., GDPR, CCPA) and map to package limitations.
  2. Installation:
    composer require spatie/laravel-cookie-consent
    php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-config"
    
    • Configure .env and config/cookie-consent.php (e.g., COOKIE_CONSENT_ENABLED, cookie_lifetime).
  3. Integration Options:
    • Option A: Blade Inclusion (Recommended for granular control):
      @include('cookie-consent::index')
      
      • Customize via published views (resources/views/vendor/cookie-consent).
    • Option B: Middleware (Recommended for global enforcement):
      // Laravel 11: bootstrap/app.php
      ->withMiddleware(function (Middleware $middleware) {
          $middleware->append(\Spatie\CookieConsent\CookieConsentMiddleware::class);
      });
      
      • Automatically injects the banner into responses.
  4. Customization:
    • Publish translations for localization:
      php artisan vendor:publish --tag="cookie-consent-translations"
      
    • Extend functionality (e.g., decline button, consent categories) via:
      • Custom views (dialogContents.blade.php).
      • Middleware to block scripts until consent (e.g., App\Http\Middleware\BlockTrackers).
  5. Testing:
    • Validate cookie persistence across sessions/subdomains.
    • Test edge cases (e.g., private/incognito mode, cookie deletion).

Compatibility

  • Pros:
    • Laravel: Works out-of-the-box with Laravel’s session/cookie system.
    • Frontend: No JS framework lock-in; works with vanilla JS, Alpine.js, or React/Vue via Blade.
    • Multi-Language: Supports 30+ locales (e.g., en, fr, de) with easy customization.
  • Cons:
    • Non-Laravel Stacks: Not suitable for non-PHP backends (e.g., Node.js, Python).
    • SPAs/Headless: Cookie-only persistence may require additional logic (e.g., localStorage sync).
    • Legacy Laravel: Versions <9 may need manual adjustments (e.g., middleware registration).

Sequencing

  1. Phase 1: Core Implementation (2–3 days):
    • Install, configure, and integrate via middleware or Blade.
    • Customize banner text/design.
  2. Phase 2: Enforcement (1–2 days):
    • Implement middleware to block non-essential scripts until consent.
    • Test cookie persistence and edge cases.
  3. Phase 3: Localization & Compliance (1 day):
    • Publish translations for supported languages.
    • Add legal disclaimers/links to privacy policy.
  4. Phase 4: Monitoring (Ongoing):
    • Track consent rates and user behavior.
    • Plan for future updates (e.g., new consent categories).

Operational Impact

Maintenance

  • Pros:
    • Minimal: Package is stable (1500+ stars, active maintenance) with clear upgrade paths.
    • Self-Contained: No external dependencies beyond Laravel core.
    • Documentation: Comprehensive README, changelog, and Spatie’s support resources.
  • Cons:
    • Custom Extensions: Any non-standard features (e.g., decline buttons) require manual maintenance.
    • Legal Updates: Compliance rules may evolve; TPM must monitor changes (e.g., GDPR updates).
    • Deprecations: Laravel 13+ support is new (as of 2026); long-term compatibility depends on Spatie’s roadmap.

Support

  • Community:
    • GitHub issues/PRs (active community with 100+ contributors).
    • Spatie’s open-source support (e.g., postcards, paid products).
  • Internal:
    • Onboarding: Low barrier for devs (simple installation + Blade inclusion).
    • Troubleshooting: Common issues (e.g., cookie domain misconfig) are documented in the README.
    • Escalation: For critical bugs, leverage Spatie’s security contact (freek@spatie.be).

Scaling

  • Performance:
    • Negligible Impact: Cookie check and view render add <50ms to page load (benchmark in staging).
    • Caching: Middleware adds a global hook; test with high-traffic endpoints.
  • Multi-Region:
    • Cookie domain/subdomain support is configurable via SESSION_DOMAIN in
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony