dedecube / laravel-legal-consent
Laravel Legal Consent
Requires
- php: ^8.1|^8.2
- ext-json: *
- dedecube/laravel-composer: ^0.0.2
- illuminate/database: ^9.0|^10.0|^11.0
- illuminate/http: ^9.0|^10.0|^11.0
- illuminate/routing: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
- laravel/prompts: ^0.1.8
- spatie/laravel-package-tools: ^1.14.1
Requires (Dev)
- laravel/nova: ^4.27
- laravel/pint: ^1.13
- orchestra/testbench: ^7.0|^8.0
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.20
Suggests
- laravel/nova: Required to use the Nova resources provided by this package.
This package is auto-updated.
Last update: 2024-09-20 13:34:31 UTC
README
Laravel Legal Consent
轻松将法律文件(如隐私政策、使用条款等)集成到您的应用程序中。
安装
您可以通过composer安装此包
composer require dedecube/laravel-legal-consent
您可以使用以下命令发布并运行迁移
php artisan vendor:publish --tag="legal-consent-migrations"
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="legal-consent-config"
使用方法
基本
要使用此包,请将Dedecube\LegalConsent\HasLegalConsent
特性添加到您要处理的任何Authenticatable模型中。
以下是将HasLegalConsent
特性添加到User的示例
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Dedecube\LegalConsent\HasLegalConsent; class User extends Authenticatable { use HasLegalConsent; // }
完成之后,您必须通过在config/legal-consent.php
中的allowed_document_types
列表中添加它们来定义允许的文档类型列表。
'allowed_document_types' => [ 'privacy-policy', 'terms-of-use', ],
然后,您可以从数据库中创建一个或多个文档,或者如果您愿意,也可以使用CMS来处理创建。
以下是需要填写字段
- type:文档类型名称
- body:文档内容
- noted:为文档显示的附加注释
- published_at:给定文档的发布日期
假设我们创建一个于2021-01-01发布的隐私政策文档:以下是我们将拥有的模型实体
$legalDocument = [ "id" => 1, "type" => "privacy-policy", "body" => "The privacy policy's very long text", "notes" => "", "published_at" => "2021-01-01", "updated_at" => "2021-01-01", "created_at" => "2021-01-01", ];
现在,您可以调用自定义API以检索和接受当前文档,这些可以在config/legal-consent.php
中自定义
GET - /legal/documents/privacy-policy
此端点使用给定的标准检索当前法律文档
- 文档类型必须是
privacy-policy
- published_at日期必须早于
now()
然后,根据published_at日期对文档条目进行排序,以便选择最新发布的。
响应包含文档id(用于POST路由)以及所有对渲染有用的信息。以下是一个示例响应体
{ "data": { "id": 1, "type": "privacy-policy", "body": "The privacy policy's very long text", "notes": "", "published_at": "2021-01-01" } }
POST - /legal/documents/{id}
此端点存储当前认证用户对给定文档的同意。
法律文档监听器
您最终可以使用我们的监听器接受所有活动法律文档。
例如,当您的应用程序处理用户的注册,并且他们必须在继续之前通过复选框接受所有法律文档时,这可能很有用。
在这种情况下,您只需将监听器添加到EventServiceProvider
中的Registered
事件即可。
use Dedecube\LegalConsent\Listeners\AcceptLegalDocumentListener; /** * The event listener mappings for the application. * * @var array */ protected $listen = [ Registered::class => [ AcceptLegalDocumentListener::class, // all currently active legal documents will be accepted SendEmailVerificationNotification::class, ], ];
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全漏洞
有关如何报告安全漏洞的更多信息,请参阅我们的安全策略。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。