scify/laravel-cookies-consent
A ready-to-use cookie consent solution for Laravel: display a customizable consent banner, manage cookie categories, log user consent, and restrict scripts until approval. Includes middleware, Blade views, config options, and multi-language support for GDPR-friendly compliance.
composer require scify/laravel-cookie-guard, then publish the package assets and configuration. The public assets are published with php artisan vendor:publish --tag="cookies-consent-public"; use the package's other publish tags for config, views and translations as needed.required, and which cookie names belong to each category. These name entries are what the package erases when a visitor rejects or later withdraws consent.use_separate_page mode, add the separate consent page as well.web middleware group, so the JavaScript must be able to send a token. The component looks for data-csrf-token on the banner root, then the csrf-token meta tag. In a standard Blade layout, include <meta name="csrf-token" content="{{ csrf_token() }}">.lang/vendor/cookies_consent/{locale}/messages.php.name. The server validates the posted consent payload as one boolean per configured category plus locale; anything else is dropped. Treat the config as the single source of truth for both the UI and the erasure logic.required for non-optional categories. Required categories are always stored as accepted, regardless of what the browser sends. "Reject optional" keeps every category listed in required, not only strictly_necessary.cookie_lifetime. This now governs the consent cookie the browser stores. 0 keeps consent for the browser session only. The old hardcoded 30-day behaviour is gone.use_separate_page for a dedicated settings page. The 5.1 release fixes "Accept all" and "Reject optional" in this mode by rendering the category list on the banner root. If you have custom markup for this mode, include the new data attributes.#consent-settings or a hash change after page load. Both open the banner; they no longer toggle it. This is the right hook for a footer "Cookie settings" link./guard-settings/save, send the CSRF token (X-XSRF-TOKEN, _token, or the X-XSRF-TOKEN cookie pattern used by the package). Expect a 422 if any category value is not a boolean.data-cookie-lifetime, data-cookie-categories, data-required-categories, data-csrf-token) intact. Re-publishing over custom views will discard your changes; diff before using --force.lang/vendor/cookies_consent/ and keep only the strings you change. Laravel merges the rest, so later fixes arrive automatically.node:test coverage for the JavaScript bundle. Mirror that split in your app: assert the rendered category list and attributes in PHP, and exercise accept/reject/save flows in a browser or JS test.XSRF-TOKEN cookie being sent as X-XSRF-TOKEN, so consent saves keep working on pages that never reload.php artisan vendor:publish --tag="cookies-consent-public" --force. Old JavaScript does not read the new root attributes.data-cookie-lifetime, data-cookie-categories, data-required-categories and data-csrf-token manually.0/1 if your client is strict. Unknown keys are dropped rather than rejected.required.name. The package deletes on the host and parent domains down to the registrable domain, but it cannot remove cookies you forgot to declare.enabled config key is gone. Nothing read it; initial checkbox state comes from required only. Remove it from your config to avoid confusion.se to sv. If your app uses locale se, switch it or your translations will not resolve.lang/vendor/scify/laravel-cookie-guard/ is read with a log warning. Move changed strings to lang/vendor/cookies_consent/{locale}/messages.php and delete the old directory now rather than at v6.{cookie_prefix}cookies_consent_selection never reached the browser and is gone, as is the pre-v3 cookieConsent eraser.SameSite=Lax, and Secure on HTTPS pages. If you inspect cookies over plain HTTP in development, expect the Secure flag to be absent there.How can I help you explore Laravel packages today?