devrabiul/laravel-cookie-consent
GDPR-compliant cookie consent for Laravel with one-click setup and no frontend dependencies. Fully customizable banners with RTL/i18n, dark mode, responsive UI, and granular category controls (necessary/analytics/marketing) for enterprise-grade compliance.
{!! CookieConsent::styles() !!}) for seamless UI injection, reducing frontend coupling.vendor:publish command for config/assets. No frontend dependencies (e.g., jQuery) simplify adoption.config/cookie-consent.php allows team-wide consistency while supporting per-environment overrides (e.g., env('COOKIE_CONSENT_ANALYTICS')).ConsentUpdated) for audit logging or analytics sync.setcookie(); ensure server config (e.g., session.cookie_lifetime) aligns with package defaults (7-day lifetime).loadGoogleAnalytics) must be manually implemented, risking inconsistency if not version-controlled.COOKIE_CONSENT_ASSET_URL) require CDN or local storage setup for production.Laravel_App) avoid conflicts across tenants?composer require devrabiul/laravel-cookie-consent.php artisan vendor:publish --provider="Devrabiul\CookieConsent\CookieConsentServiceProvider"./privacy-policy) using the basic Blade includes.config('cookie-consent.enabled')) to A/B test UX impact.loadGoogleAnalytics) in a shared JS file or Laravel Mix entry point.app('cookie-consent')->getConsent() to dynamically load scripts based on user preferences.showHideToggleCookiePreferencesModal) don’t conflict with SPA routing.php artisan view:clear) after config changes to avoid stale styles.| Step | Task | Owner | Dependencies |
|---|---|---|---|
| 1 | Install package | DevOps | Composer access |
| 2 | Publish config/assets | Backend | Step 1 |
| 3 | Configure cookie categories | PM/Dev | Legal review |
| 4 | Implement JS handlers | Frontend | Step 3 |
| 5 | Test consent flow | QA | Steps 1–4 |
| 6 | Integrate with analytics | Analytics | Step 5 |
| 7 | Deploy to production | DevOps | Step 6 |
cookie-consent.php reduces drift but requires version control (e.g., Git) for environment-specific tweaks.CookieConsent::old()) if Laravel core evolves.Log::channel('cookie-consent')->info() to track consent changes for compliance.consents table for:
SameSite attributes may need adjustment for global deployments (consult Laravel’s cookie docs).| Scenario | Impact | Mitigation |
|---|---|---|
| JS Fails to Load | Cookie banner invisible | Fallback: Server-side cookie check via request()->cookie('Laravel_App_consent'). |
| Config Misconfiguration | Broken UI or missing categories | Validate config schema with Laravel’s config:validate or a custom Artisan command. |
| Cookie Blocked by Browser | User loses preferences | Use localStorage as a backup (requires JS polyfill). |
| Legal Changes | Outdated cookie categories | Designate a "compliance owner" to review annually. |
loadGoogleAnalytics to resources/js/cookie-consent.js").session.cookie_domain").$consents = DB::table('consents')->where('category', 'analytics')->count();
How can I help you explore Laravel packages today?