Download the PHP package stevecreekmore/cookies without Composer
On this page you can find all versions of the php package stevecreekmore/cookies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stevecreekmore/cookies
More information about stevecreekmore/cookies
Files in stevecreekmore/cookies
Package cookies
Short Description A Laravel package for managing cookie consent and GDPR compliance
License MIT
Homepage https://github.com/stevecreekmore/cookies
Informations about the package cookies
Laravel Cookie Consent
A GDPR-compliant Laravel package for managing cookie consent with category-based consent management, script blocking, consent logging, and easy withdrawal.
Features
- ✅ GDPR Compliant - Meets all major GDPR requirements
- 🚫 Script Blocking - Prevents non-consented scripts from loading
- 📝 Consent Logging - Database audit trail of all consent actions
- 🔄 Easy Withdrawal - Users can change their mind anytime
- 📊 Detailed Cookie Information - Show specific cookies, purposes, and durations
- 🎨 Fully Customizable - Themes, positioning, and text
- 🔌 Blade Directives - Easy integration with existing code
- 🌐 Event System - React to consent changes in JavaScript
- 📱 Responsive Design - Works on all devices
GDPR Compliance
This package helps you comply with GDPR by:
- Blocking Non-Essential Cookies - Scripts are blocked until consent is given
- Granular Consent - Users can choose specific cookie categories
- Detailed Information - Shows cookie names, purposes, durations, and providers
- Easy Withdrawal - Floating button to change preferences anytime
- Consent Logging - Audit trail stored in database (proof of consent)
- Privacy Policy Links - Direct links to your policies
- Opt-in by Default - No pre-checked boxes (except necessary cookies)
Installation
Install the package via composer:
The package will automatically register its service provider.
Publish Configuration
Publish the configuration file:
Publish Migrations (for consent logging)
Publish Views (Optional)
If you want to customize the banner appearance:
Add Middleware
Add the middleware to your bootstrap/app.php (Laravel 11+):
Or for Laravel 10 and below, add to app/Http/Kernel.php:
Configuration
Define Your Cookies
Edit config/cookies.php to define the specific cookies your site uses:
Set Policy URLs
Or in your .env:
Usage
Blocking Scripts Until Consent
The most important GDPR feature - scripts won't load until the user consents:
Method 1: Blade Directive (Recommended)
Method 2: Manual Script Blocking
The script will automatically be activated once the user consents to that category.
Checking Consent in PHP
Blade Conditional Directive
JavaScript Event Listener
React to consent changes in your JavaScript:
GDPR Compliance Features
1. Consent Logging (Audit Trail)
All consent actions are logged to the database:
2. Consent Withdrawal
A floating button appears after consent is given, allowing users to:
- Change their preferences
- Withdraw consent completely
- View what they previously accepted
This is a GDPR requirement - withdrawal must be as easy as giving consent.
3. Detailed Cookie Information
Users can click "View Cookie Details" to see a table with:
- Cookie names
- Purpose of each cookie
- Duration/expiry
- Provider (first-party or third-party)
4. Log Retention
Control how long consent logs are kept (GDPR requires keeping records):
Clean up old logs:
Or schedule it in app/Console/Kernel.php:
Customization
Styling
Customize appearance in config/cookies.php:
Custom Text
Change all text and labels:
Custom Banner View
After publishing views, edit resources/views/vendor/cookies/banner.blade.php for complete control.
Disable Consent Logging
If you don't need database logging:
Hide Settings Button
Testing
This package comes with a comprehensive test suite using Pest.
Running Tests
Test Coverage
The package includes 80+ test cases covering:
- CookieConsent Class - All consent checking methods
- ConsentLogger Service - Database logging functionality
- Middleware - Banner injection and HTML response handling
- CookieConsentLog Model - Database operations and cleanup
- ConsentController - API endpoint validation
- Blade Directives - Template rendering and conditional display
- Facade - All facade methods
- Architecture - Code quality and security standards
Requirements for Testing
The test suite requires:
- PHP ^8.4
- Laravel ^12.0
- SQLite (for in-memory testing)
All dependencies are automatically installed via composer install.
Best Practices for GDPR Compliance
- Document All Cookies - Fill in the
cookiesarray for each category with specific cookie details - Update Your Privacy Policy - Include information about cookie usage
- Block All Non-Essential Scripts - Use the Blade directive or manual blocking
- Keep Consent Logs - Enable database logging for proof of consent
- Regular Audits - Review what cookies your site actually sets
- Honor Withdrawals - The floating button makes this easy
- Third-Party Cookies - List all third-party providers clearly
API Reference
Facade Methods
Blade Directives
JavaScript Events
Troubleshooting
Scripts Not Loading After Consent
Make sure you're using type="text/plain" and the data-cookie-consent attribute:
Banner Not Showing
- Check middleware is added to web routes
- Ensure
COOKIE_CONSENT_ENABLED=truein.env - Check if consent cookie already exists (delete it to test)
Consent Not Being Logged
- Run migrations:
php artisan migrate - Check
COOKIE_CONSENT_LOG=truein config - Ensure CSRF token is present on the page:
<meta name="csrf-token" content="{{ csrf_token() }}">
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Steven Creekmore
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of cookies with dependencies
illuminate/support Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0