mrshanebarron/cookie-consent
Laravel package for GDPR-friendly cookie consent. Adds a configurable consent banner, cookie categories, and middleware to block scripts until visitors opt in. Publishable config and views make it easy to match your app's design and store consent records.
composer require mrshanebarron/cookie-consent
php artisan vendor:publish --provider="MrShaneBarron\CookieConsent\CookieConsentServiceProvider" --tag=config
php artisan vendor:publish --provider="MrShaneBarron\CookieConsent\CookieConsentServiceProvider" --tag=views
php artisan vendor:publish --provider="MrShaneBarron\CookieConsent\CookieConsentServiceProvider" --tag=lang
Since v1.0.2 fixes PascalCase class naming for hyphenated names, double-check the published tags/namespaces against config/cookie-consent.php and the package's composer.json — the exact provider string may differ from the guess above.config/cookie-consent.php. This is the single source of truth for banner text, button labels, styling, and cookie lifetime. Everything else in the package flows from these keys.resources/views/layouts/app.blade.php) so it renders on every page:
<x-cookie-consent />
If the component alias differs, check the package's Blade service provider registration or the views/components directory after publishing.@if (cookie_consent_accepted())
<script src="https://www.googletagmanager.com/gtag/js?id=G-XXXX"></script>
@endif
The exact helper name is the one detail most worth verifying against the source — the description promises a "helper/API to gate analytics," but not its signature.<x-cookie-consent /> once in your master layout. The package reads its own cookie, so re-rendering on every request is cheap and avoids middleware ordering problems.@cookieConsent
<script>/* analytics, pixels, chat widgets */</script>
@endcookieConsent
(Blade directive name may vary — confirm in the service provider's boot() method.) This keeps gating visible next to the script it protects, which is far easier to audit than a central registry.lang files, key the banner copy by locale, and set app.locale normally. Keep legally required text (e.g., "We use cookies to…", "Accept"/"Reject"/"Manage") in translation files rather than config so translators own them.composer dump-autoload and php artisan optimize:clear after upgrading, given v1.0.2's class-rename fix.Class not found. Grep your app for the old names before deploying, and confirm the package ships backward-compatible aliases — if it doesn't, treat v1.0.2 as a breaking change.composer dump-autoload -o plus php artisan config:clear route:clear view:clear cache:clear resolves the majority of "works locally, broken in prod" reports with this kind of patch release.php artisan about / bootstrap/providers.php. (2) Did config publish? php artisan config:show cookie-consent. (3) Is the Blade component registered? php artisan view:clear then inspect the rendered HTML for the banner's root element. (4) Is the cookie actually being set? Inspect in devtools, then confirm the helper reads it.App\Support\Consent) so swapping packages later is a one-file change rather than a repo-wide grep.How can I help you explore Laravel packages today?