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 Cookie Consent Laravel Package

whitecube/laravel-cookie-consent

View on GitHub
Deep Wiki
Context7

Register, configure and ask for cookies consent in a EU-compliant way

Frequently asked questions about Laravel Cookie Consent
How do I install and set up Laravel Cookie Consent in my Laravel 11 project?
Run `composer require whitecube/laravel-cookie-consent` to install the package. Then publish the configuration and views with `php artisan vendor:publish --tag=laravel-cookie-consent`. The package integrates seamlessly with Laravel’s service provider pattern, requiring minimal manual setup for basic functionality.
Does this package work with Laravel 9 or older versions?
No, this package is designed for Laravel 9+ (PHP 8.0+) and Laravel 11+. If you’re using an older Laravel version, you’ll need to check for alternative packages or upgrade your project to meet the package’s requirements.
Can I customize the cookie consent modal’s appearance and behavior?
Yes, the package is fully customizable. You can override the default Blade views, modify the JavaScript behavior, and adjust styling via CSS. The documentation provides clear guidance on how to publish and extend the default assets.
How do I register a custom cookie category (e.g., for third-party scripts like Hotjar)?
Use the `Cookies::registerCategory()` method in your service provider’s boot method. Define the category name, description, and any default settings. For example, `Cookies::registerCategory('analytics', 'Analytics Cookies', true)` registers a new category for analytics tools.
What happens if a user denies consent for analytics cookies but Google Analytics is still loaded?
The package dynamically injects scripts only after consent is granted. If a user denies consent for analytics cookies, Google Analytics (or any other third-party script) will not load. This is handled automatically via the `@cookieconsentscripts` Blade directive.
Is there a way to store cookie consent preferences in a database instead of cookies/sessions?
Yes, the package is designed to be extensible. You can override the default storage mechanism by binding a custom consent repository to the `cookie-consent.repository` service provider binding. This allows you to persist consent preferences in a database table.
Will this package slow down my Laravel application or impact Core Web Vitals?
The package is lightweight and only loads the consent modal or scripts when necessary. However, dynamically injecting third-party scripts (e.g., Google Analytics) after consent can impact performance. Test your application with tools like Lighthouse to ensure compliance with Core Web Vitals.
Can I use this package with a frontend framework like Vue or React instead of Blade?
Yes, the package works with any frontend framework as long as you include the Blade directives (`@cookieconsentscripts` and `@cookieconsentview`) in your templates. For Vue or React, you can render these directives in your components or use them in server-side rendering.
What are the risks of misconfiguring cookie categories or durations?
Misconfiguring cookie categories (e.g., marking essential cookies as non-essential) can break core functionality. Setting incorrect durations may violate GDPR requirements. Always test your configuration thoroughly, especially for essential cookies, and validate with tools like browser dev tools or cookie editors.
Are there alternatives to this package that don’t rely on JavaScript for cookie consent?
Yes, if you prefer a purely server-side solution, consider alternatives like `laravel-cookieconsent` or `gloudemans/cookieconsent`. However, this package offers a balanced approach by providing both JavaScript-dependent and JavaScript-free flows, ensuring accessibility and flexibility.
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