origami / consent
Laravel项目中用户同意的辅助接口
2.4.0
2024-05-28 12:18 UTC
Requires
- php: ^7.2|^8.0.2
- illuminate/contracts: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/database: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/events: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^3.8|^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^7.0|^8.0|^9.0|^10.0
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');
贡献
请提交改进和修复:)