riclep/cookie-law
适用于遗留Laravel 4项目的非常基础的cookie法律包
0.0.8
2022-05-17 15:32 UTC
Requires
- php: >=5.4.0
- illuminate/support: 4.2.*
README
显示一个包含消息和接受按钮的对话框。接受cookie的默认名称为:laravel_cookie_acceptance
。您负责根据他们的接受来实现逻辑!
### 使用Blade检查接受情况
@if (isset($_COOKIE[Config::get('cookie-law::cookie-law.cookie_name')]))
// Cookie is accepted to do stuff here
@endif
### 安装
composer require riclep/cookie-law
添加服务提供者
'RicLeP\CookieLaw\CookieLawServiceProvider',
添加到 config/app
在模板底部附近包含Blade视图。
@include('cookie-law::dialog')
如果需要编辑任何内容,则发布配置文件
php artisan config:publish riclep/cookie-law
要创建cookie页面,请从包中复制控制器和视图占位符,并根据网站进行调整。然后可以将以下行添加到路由文件中
Route::get(Config::get('cookie-law::cookie-law.cookie_url'), 'CookiesController@view');
要覆盖文字,在 app/lang/packages/{locale}/cookie-law/lang.php
中创建一个语言文件,内容如下
<?php return array ( 'message' => '', 'accept-button' => '', 'reject-button' => '', 'customise-button' => '', 'details' => '', 'categories' => array( '' => '', '' => '', //e.g. 'Analytics cookies' => '' ), 'accepted' => '', 'rejected' => '', );
### JavaScript和样式
此包没有默认样式,但使用BEM样式类。
/* The container element */ .cookie-law {} /* Class applied via JS when the accept button is hit - use this to hide the dialog */ .cookie-law--accepted {} /* Inner element should you want to the container to span but fix the width of the contents */ .cookie-law__inner {} /* Container for the message to be shown */ .cookie-law__message {} /* The accept button styling */ .cookie-law__button {}