distcz/laravel-cookie-consent-history

该包允许您简单地存储用户的cookie同意历史,以便在检查或其他不幸事件发生时以后访问。

v1.0.0 2022-01-27 13:20 UTC

This package is auto-updated.

Last update: 2024-08-27 18:43:08 UTC


README

Latest Version on Packagist Total Downloads

此包旨在使将匿名cookie同意存储在数据库中以符合严格的欧盟cookie政策法规变得简单。您的应用程序将获得保持同意历史记录的能力,因此当有人对您的cookie同意提出投诉时,您将不会在证据负担过程中遇到问题。

安装

您可以通过composer安装此包

composer require dystcz/laravel-cookie-consent-history

发布配置和迁移,运行迁移

php artisan vendor:publish --provider="Dystcz\CookieConsentHistory\CookieConsentHistoryServiceProvider"
php artisan migrate

在您的某些路由文件中注册包的路由,但如果您想使用自己的路由和控制器,那是完全可以的。

// routes/api.php

use Dystcz\CookieConsentHistory\CookieConsentHistoryFacade;

CookieConsentHistoryFacade::routes();

配置

return [
    /**
     * The prefix for the table names.
     * You can use your own prefix here, eg. company_ if it were to conflict with existing table names.
     * We leave it empty, so the table name is cookie_consents by default.
     */
    'table_prefix' => '',

    /**
     * The prefix for routes.
     * There are only 2 routes, one for storing the consent data and one for retrieving.
     *
     * POST /cookie-consents (or your prefix) saves the consent
     * GET /cookie-consents/{id} gets the consent if exists
     */
    'route_prefix' => 'cookie-consents',

    /**
     * Model definition.
     * You can extend the base model to your needs.
     */
    'model' => Dystcz\CookieConsentHistory\Models\CookieConsent::class,
];

用法

存储同意

您可以注册包的路由,或者您可以通过控制器引入自己的路由。

以下是一个示例存储方法,来自 Dystcz\CookieConsentHistory\Http\Controllers\CookieConsentsController

/**
* Store cookie consent data.
*
* @param StoreCookieConsentRequest $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function store(StoreCookieConsentRequest $request)
{
    // Create DTO out of validated request
    $data = new CookieConsentData(...$request->validated());

    $consent = CookieConsentHistory::save($data);

    return new JsonResponse([
        'data' => $consent,
    ]);
}

补充前端包

我们旨在提供补充的javascript包,该包将与此包很好地配合使用,使cookie法规符合变得尽可能简单。

敬请期待。

测试

即将推出测试!

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全

如果您发现任何与安全相关的问题,请通过电子邮件jakub@dy.st联系,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件