origami/consent

Laravel项目中用户同意的辅助接口

2.4.0 2024-05-28 12:18 UTC

This package is auto-updated.

Last update: 2024-08-31 13:12:14 UTC


README

关于

origami/consent辅助包包含一个Laravel模型特性,用于简化保存、比较和撤销同意的过程。该包将所有同意更新保存到consent表中,并为如用户模型等模型提供了GivesConsent特性。

该包的产生源于GDPR和英国信息专员办公室关于“同意”的指南

安装

此包适用于Laravel >= 6.0。您可以通过composer拉取此包。

composer require origami/consent

您应该使用以下命令发布同意表迁移

php artisan vendor:publish --provider="Origami\Consent\ConsentServiceProvider" --tag="migrations"

迁移数据库

php artisan migrate

使用方法

要使用此包,请将GivesConsent特性添加到您想要跟踪同意的模型中。

use Origami\Consent\GivesConsent;

class User extends Model {

  use GivesConsent;

}

给出同意

您可以这样标记明确的同意

$model->giveConsentTo('consent-name');

GDPR要求您记录当时显示的确切内容。您可以在text属性中这样做,并通过meta传递任何额外信息

$model->giveConsentTo('consent-name', [
  'text' => 'You are consenting to ...',
  'meta' => [
    'ip' => '192.168.0.1',
  ]
]);

给出同意

您可以这样撤销用户的同意

$model->revokeConsentTo('consent-name');

检查同意

您可以这样检查是否给出了同意

if ( $model->hasGivenConsent('consent-name') ) {

}

如果未设置同意,则默认为false。您可以在第二个参数中更改它。

if ( $model->hasGivenConsent('consent-name', true) ) {

}

当前同意

您可以这样获取用户的当前同意状态。这将是一个Origami\Consent\Consent实例

$consent = $model->getConsent('consent-name');

贡献

请提交改进和修复:)

作者

Papertank Limited

许可

查看许可