ideacatlab/laravel-cookie-consent-enhanced
Composer 安装命令:
composer require ideacatlab/laravel-cookie-consent-enhanced
包简介
Make your Laravel app comply with the EU cookie law and implement a cookie control system that allows users to manage their own cookie preferences
关键字:
README 文档
README
Elevate Your Laravel App's GDPR Compliance with Enhanced Cookie Consent
Ensuring compliance with EU laws on cookie usage is crucial for websites targeting or owned by EU citizens. Dive into the capabilities of this Laravel package, a robust extension originating from Spatie's Laravel Cookie Consent. Developed by IdeaCat, a web development agency in Bucharest, Romania, this package not only simplifies the implementation of a cookie consent dialog but also extends its functionalities. Beyond the essentials, it introduces advanced features like predefined database tables, administrative tools for user data management, and seamless integration of GDPR compliance requirements.
Explore further details about the EU legislation on cookies here.
Installation and Configuration
1. Install the Package
You can effortlessly install the package via Composer. Open your terminal and run:
composer require ideacatlab/laravel-cookie-consent-enhanced
The package will automatically register itself in your Laravel application.
2. Publish Vendor Files
Run the publish command to publish the views, languages, database migration, config and assets.
php artisan vendor:publish --provider="Ideacatlab\LaravelCookieConsentEnhanced\CookieConsentServiceProvider"
3. Migrate the Database
Execute the migration command to create the required database tables:
php artisan migrate
Configuration Details
Upon publishing the configuration file, you'll find a file named cookie-consent-enhanced.php in the config directory. Here's an overview of the configuration options:
return [ /* * Use this setting to enable the cookie consent dialog. */ 'enabled' => env('COOKIE_CONSENT_ENABLED', true), /* * The name of the cookie in which we store if the user * has agreed to accept the conditions. */ 'cookie_name' => 'cookie_consent', /* * Set the cookie duration in days. Default is 365 * 20. */ 'cookie_lifetime' => 365 * 20, ];
Note on Cookie Domain
Ensure you set the cookie domain by using the 'domain' key in the config/session.php file. Add the corresponding value in your .env file for SESSION_DOMAIN. If your URL includes a port, such as 'localhost:3000', it is crucial to set this value for the package to function correctly.
Usage and Customization
Displaying the Cookie Consent Dialog Using Blade Template
To effortlessly display the cookie consent dialog in your template, include the following line in your Blade file:
@include('cookie-consent-enhanced::index')
This will render a dialog similar to the one depicted below. Note that the default styling, powered by TailwindCSS v2, creates a floating banner at the bottom of the page.
Displaying the Cookie Consent Dialog Using the Middleware
Instead of manually including cookie-consent-enhanced::index in your view, consider adding the middleware to your kernel:
// app/Http/Kernel.php class Kernel extends HttpKernel { protected $middleware = [ // ... \Ideacatlab\LaravelCookieConsentEnhanced\CookieConsentMiddleware::class, ]; // ... }
This will automatically add cookie-consent-enhanced::index to your response just before the closing body tag.
Upon clicking "Allow cookies," a cookie_consent cookie will be set, and the dialog will be removed from the DOM. Laravel, recognizing the set laravel_cookie_consent cookie on subsequent requests, will refrain from displaying the dialog again.
Customizing Dialog Texts
The files is published to resources/lang/vendor/cookie-consent-enhanced/en/texts.php. You can then customize the text as follows:
return [ 'message' => 'Please be informed that this site uses cookies.', 'agree' => 'Allow cookies', ];
For translations, copy the file to, for instance, resources/lang/vendor/cookie-consent-enhanced/fr/texts.php and provide the French translations.
Customizing Dialog Contents
The files is published to the index and dialogContents view files to resources/views/vendor/cookie-consent-enhanced. Typically, you only need to modify the dialogContents view. Adjusting the JavaScript code is possible in the index view file.
Testing
Execute the following command to run tests:
composer test
Security
If you discover any security-related issues, please contact razvan@ideacat.ro instead of using the issue tracker.
License
This project is licensed under the MIT License. See License File for more information.
ideacatlab/laravel-cookie-consent-enhanced 适用场景与选型建议
ideacatlab/laravel-cookie-consent-enhanced 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 148 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cookie」 「Enhanced」 「eu」 「law」 「comply」 「cookie-consent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ideacatlab/laravel-cookie-consent-enhanced 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ideacatlab/laravel-cookie-consent-enhanced 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ideacatlab/laravel-cookie-consent-enhanced 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add a configurable cookie consent banner to the website.
This extension allows you enable an EU compliant consent cookie notification banner.
Generate Relational (has many) Models & CRUD.
Make your Laravel app comply with the crazy EU cookie law
A powerful, efficient analytics solution for Statamic with real-time tracking, caching, and comprehensive dashboard visualization.
Generate Relational (hasMany, hasOne, belongsTo, & nested) Models & CRUD.
统计信息
- 总下载量: 148
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-25

