amoori / cookie-consent
让您的Laravel应用程序符合疯狂的欧盟cookie法规
Requires
- php: ^7.2
- illuminate/cookie: ~5.8.0|^6.0|^7.0|^8.0
- illuminate/support: ~5.8.0|^6.0|^7.0|^8.0
- illuminate/view: ~5.8.0|^6.0|^7.0|^8.0
Requires (Dev)
- fzaninotto/faker: ~1.4
- orchestra/testbench: ~3.8.0|^4.0|^5.0|^6.0
This package is auto-updated.
Last update: 2024-09-22 12:04:52 UTC
README
所有由欧盟公民拥有或针对欧盟公民的网站都必须遵守一项疯狂的欧盟法律。该法律要求显示一个对话框,向用户告知您的网站如何使用cookie。您可以在欧洲委员会网站上了解更多关于该法规的信息:欧洲委员会网站。
此包提供了一个易于配置的视图来显示消息。还包括JavaScript代码,当用户同意cookie策略时设置cookie。当设置了该cookie时,包将不会显示对话框。
Spatie是一家位于比利时安特卫普的网页设计公司。您可以在我们的网站上找到我们所有开源项目的概述:我们的网站。
支持我们
通过观看我们的高级视频课程,了解如何创建此类包
我们投入了大量资源来创建最佳开源包。您可以通过购买我们的付费产品之一来支持我们。
我们非常感谢您从您的家乡寄来明信片,并说明您正在使用我们的哪个包。您可以在我们的联系页面上找到我们的地址。我们将发布收到的所有明信片在我们的虚拟明信片墙上。
安装
您可以通过composer安装此包
composer require spatie/laravel-cookie-consent
包将自动注册自己。
可选:您可以选择发布配置文件
php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="config"
这是发布配置文件的内容
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' => 'laravel_cookie_consent', /* * Set the cookie duration in days. Default is 365 * 20. */ 'cookie_lifetime' => 365 * 20, ];
用法
要显示对话框,只需在您的模板中包含此视图即可
//in your blade template @include('cookieConsent::index')
这将渲染以下对话框,当样式化时,将非常类似于这个。
请注意,该包不提供任何样式,这是您需要自己完成的。
当用户点击“允许cookies”时,将设置一个laravel_cookie_consent
cookie,并从DOM中删除对话框。在下一次请求时,Laravel将注意到已设置了laravel_cookie_consent
,并且不会再次显示对话框。
自定义对话框文本
如果您想修改对话框中显示的文本,可以发布lang文件,使用以下命令
php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="lang"
这将此文件发布到resources/lang/vendor/cookieConsent/en/texts.php
。
return [ 'message' => 'Please be informed that this site uses cookies.', 'agree' => 'Allow cookies', ];
如果您想将这些值翻译成,例如,法语,只需将此文件复制到resources/lang/vendor/cookieConsent/fr/texts.php
并填写法语文本。
自定义对话框内容
如果您需要完全控制对话框的内容,可以发布包的视图
php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="views"
这将复制index
和dialogContents
视图文件到resources/views/vendor/cookieConsent
。您可能只想修改dialogContents
视图。如果您需要修改此包的JavaScript代码,可以在index
视图文件中这样做。
使用中间件
您可以选择在视图中包含 cookieConsent::index
,而不是将其添加到内核中 Spatie\CookieConsent\CookieConsentMiddleware
// app/Http/Kernel.php class Kernel extends HttpKernel { protected $middleware = [ // ... \Spatie\CookieConsent\CookieConsentMiddleware::class, ]; // ... }
这将自动将 cookieConsent::index
添加到响应内容中,位于关闭 body 标签之前。
注意
关于如何显示警告、必要的文本以及需要提供哪些选项,立法非常模糊。本软件包将大大有助于合规,但如果您想要确保您的网站完全符合要求,您应该咨询法律专家。
更新日志
有关最近更改的更多信息,请参阅 更新日志
测试
composer test
贡献
有关详细信息,请参阅 贡献指南
安全
如果您发现任何与安全相关的问题,请通过电子邮件 freek@spatie.be 而不是使用问题跟踪器。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件