fet/laravel-cookie-consent
Composer 安装命令:
composer require fet/laravel-cookie-consent
包简介
A simple Laravel wrapper around the orestbida/cookieconsent package.
关键字:
README 文档
README
The fet/laravel-cookie-consent package is a simple Laravel wrapper around the orestbida/cookieconsent package.
Installation
composer require fet/laravel-cookie-consentphp artisan vendor:publish --provider="Fet\CookieConsent\CookieConsentServiceProvider" --tag="config"
Configuration
// config/cookieconsent.php return [ 'enable' => true, 'routes' => [ 'post' => '', 'redirect' => '', ], 'paths' => [ 'exclude' => [] ], 'config' => [], ];
The configuration consists of four keys: enable, routes, paths and config. The config value is an array representation of the Configuration object and is passed to the CookieConsent package as JSON. Feel free to configure the package as you like.
POST Route
The Callback/Events are not directly configurable. Instead you can define a routes.post which corresponds to an existing route name which is then called via POST request when the events onFirstConsent or onChange are triggered.
If the
routes.postis empty, no POST request is sent.
The data received by the controller looks like this:
{
"consentId": "xxx",
"acceptType": "all",
"acceptedCategories": [
"necessary",
"analytics"
],
"rejectedCategories": [],
"custom": {}
}
Redirect Route
If you want to perform a page redirect after the user has made the cookie consent choice, you can provide a route name to routes.redirect.
If the
routes.redirectis empty, no redirect is made.
Exclude Paths
To exclude the cookie consent from appearing on certain URL paths, add those paths to the paths.exclude configuration array.
You can use valid regex patterns. For example, to exclude all
/admin/*paths, addadmin(\/.*)?to the exclude array.
Events
Sometimes you may need to change the configuration, after the application is booted. You can do so by listening to the \Fet\CookieConsent\Events\ConfigLoaded event.
use Fet\CookieConsent\Events\ConfigLoaded; Event::listen(function (ConfigLoaded $event) { $config = $event->cookieConsent->config; // make changes to the $config array $event->cookieConsent->config = $config; });
Custom POST data
To include custom data in the POST request, set the custom key in the configuration. This data will be sent alongside the consent information.
$config['custom'] = ['foo' => 'bar'];
Tests
Run the tests with:
composer test
fet/laravel-cookie-consent 适用场景与选型建议
fet/laravel-cookie-consent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 809 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「cookie-consent」 「gdpr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fet/laravel-cookie-consent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fet/laravel-cookie-consent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fet/laravel-cookie-consent 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple cookie consent module for magento. It relies on new GTM consent functionality.
Cookie consent for Laravel
Make your Laravel app comply with the crazy EU cookie law
This bundle contains functionality concerning privacy and the European Union's "General Data Protection Regulation" (GDPR, in German: "Datenschutz-Grundverordnung", DSGVO).
livewire cookie consent modals with laravel livewire
Symfony 8 bundle for GDPR/DSGVO cookie consent with Google Consent Mode v2, Twig components, Stimulus.js, and AssetMapper. Supports cookie, Doctrine, or combined storage. Includes YouTube, Vimeo, Google Maps embed components.
统计信息
- 总下载量: 809
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-13