fet/laravel-cookie-consent 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fet/laravel-cookie-consent

最新稳定版本:0.4.0

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

  1. composer require fet/laravel-cookie-consent
  2. php 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.post is 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.redirect is 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, add admin(\/.*)? 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

统计信息

  • 总下载量: 583
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-13