rylxes/laravel-gdpr
Composer 安装命令:
composer require rylxes/laravel-gdpr
包简介
GDPR and CCPA compliance toolkit for Laravel with data export, right to erasure, consent management, and audit trails
关键字:
README 文档
README
Full Documentation — Complete usage guide, configuration reference, and API docs.
GDPR and CCPA compliance toolkit for Laravel applications. Provides data export (portability), right to erasure, consent management, and audit trails in a single package.
Features
- Data Export (Portability) - Queue-backed export of user data as JSON, CSV, or XML with secure timed download links
- Right to Erasure - Orchestrated deletion or anonymisation respecting foreign key dependencies
- Consent Management - Audit-ready consent log with IP, user-agent, and version tracking
- Cooling-Off Period - Configurable delay before erasure execution, allowing cancellation
- Artisan Commands -
gdpr:export,gdpr:erase,gdpr:prunefor compliance officer workflows - Consent Middleware - Gate routes by consent type with
gdpr.consent:marketing - Signed Download Links - Time-limited, tamper-proof URLs via Laravel's signed routes
- CCPA Compatible - "Do not sell" opt-out support via the consent type system
- Event System -
DataExported,DataErased,ConsentRecorded,ErasureRequestedevents - Retention Policies - Configurable auto-cleanup for exports and audit logs
- Polymorphic Users - Works with any authenticatable model, not just
App\Models\User - Facade & Trait API - Use
Gdpr::export($user)or$user->recordConsent('marketing')
Installation
1. Install via Composer
composer require rylxes/laravel-gdpr
2. Run the installer
php artisan gdpr:install
This publishes the configuration file and runs migrations.
3. Implement contracts on your models
use Rylxes\Gdpr\Contracts\Exportable; use Rylxes\Gdpr\Contracts\Deletable; use Rylxes\Gdpr\Concerns\HandlesGdpr; class User extends Authenticatable implements Exportable, Deletable { use HandlesGdpr; public function exportData(): array { return $this->only(['name', 'email', 'phone', 'created_at']); } public function eraseData(): void { $this->anonymise(['name', 'email', 'phone', 'address']); } }
Apply Exportable and Deletable to any model containing personal data:
class Order extends Model implements Exportable, Deletable { use HandlesGdpr; public function exportData(): array { return $this->only(['id', 'total', 'status', 'created_at']); } public function eraseData(): void { $this->anonymise(['shipping_address', 'billing_address']); } // Child records erased before parent (lower priority = erased first) public function erasurePriority(): int { return 50; } }
Usage
Data Export
use Rylxes\Gdpr\Facades\Gdpr; // Dispatch an export job (user gets email with download link) $export = Gdpr::export($user); $export = Gdpr::export($user, 'csv'); // CSV format // Via Artisan php artisan gdpr:export 42 php artisan gdpr:export 42 --format=csv php artisan gdpr:export 42 --sync // Run synchronously
Right to Erasure
// Initiate erasure with cooling-off period $request = Gdpr::erase($user); $request = Gdpr::erase($user, 'delete', 'User requested account deletion'); // Cancel during cooling-off $request->cancel('User changed their mind'); // Via Artisan php artisan gdpr:erase 42 php artisan gdpr:erase 42 --force // Skip cooling-off php artisan gdpr:erase 42 --strategy=delete
Consent Management
// Record consent $user->recordConsent('marketing', '1.0', $request->ip()); $user->recordConsent('analytics'); // Or via facade Gdpr::recordConsent($user, 'terms_of_service', $request->ip()); // Check consent $user->hasConsent('marketing'); // true/false Gdpr::hasConsent($user, 'marketing'); // true/false // Revoke consent $user->revokeConsent('marketing'); // Get all active consent types $user->activeConsentTypes(); // ['analytics', 'terms_of_service'] // Query consent logs $user->consentLogs()->active()->get();
Consent Middleware
Gate routes that require specific consent:
Route::middleware('gdpr.consent:marketing')->group(function () { Route::get('/promotional-offers', [OffersController::class, 'index']); }); Route::middleware('gdpr.consent:analytics,tracking')->group(function () { // Requires both analytics AND tracking consent });
Data Cleanup
// Prune expired exports and old audit logs php artisan gdpr:prune php artisan gdpr:prune --force // Skip confirmation // Schedule automatic pruning (in app/Console/Kernel.php) $schedule->command('gdpr:prune --force')->daily();
Configuration
Publish the config file:
php artisan vendor:publish --tag=gdpr-config
Key Configuration Options
| Option | Default | Description |
|---|---|---|
export.default_format |
json |
Default export format (json, csv, xml) |
export.storage_disk |
local |
Filesystem disk for export files |
export.download_link_expiry_minutes |
60 |
Download link lifetime |
erasure.strategy |
anonymize |
Default: anonymize or delete |
erasure.cooling_off_days |
14 |
Days before erasure executes |
consent.version |
1.0 |
Current consent version |
consent.log_ip_address |
true |
Log IP with consent events |
queue.enabled |
true |
Queue export/erasure jobs |
queue.queue_name |
gdpr |
Queue name for GDPR jobs |
audit.consent_logs_retention_days |
2555 |
~7 years retention |
Per-Model Strategy Overrides
// config/gdpr.php 'erasure' => [ 'strategy' => 'anonymize', // default 'model_strategies' => [ App\Models\Comment::class => 'delete', App\Models\Order::class => 'anonymize', ], ],
Environment Variables
GDPR_ENABLED=true GDPR_QUEUE_ENABLED=true GDPR_QUEUE_NAME=gdpr GDPR_ERASURE_STRATEGY=anonymize GDPR_COOLING_OFF_DAYS=14 GDPR_EXPORT_FORMAT=json GDPR_DOWNLOAD_EXPIRY=60 GDPR_CONSENT_VERSION=1.0 GDPR_LOG_IP=true GDPR_CCPA_ENABLED=false
Events
Listen to GDPR events for custom integrations:
| Event | When |
|---|---|
DataExported |
After a data export is completed |
DataErased |
After user data has been erased |
ConsentRecorded |
When a user gives consent |
ErasureRequested |
When an erasure request is created |
// EventServiceProvider protected $listen = [ \Rylxes\Gdpr\Events\DataErased::class => [ \App\Listeners\NotifyDpoOfErasure::class, ], ];
Database Schema
| Table | Purpose |
|---|---|
gdpr_consent_logs |
Consent events with timestamps, IP, and version |
gdpr_erasure_requests |
Erasure request lifecycle and audit trail |
gdpr_data_exports |
Export records with download tokens and status |
All tables use a configurable prefix (gdpr_ by default).
Testing
composer test
Local Development
Add the package as a path repository in your Laravel app's composer.json:
{
"repositories": [
{
"type": "path",
"url": "../path/to/laravel-gdpr"
}
],
"require": {
"rylxes/laravel-gdpr": "*"
}
}
Then run:
composer update rylxes/laravel-gdpr php artisan gdpr:install
Security
- Download links use Laravel's
URL::temporarySignedRoute()for tamper-proof, time-limited access - Export files are stored on a configurable disk (default:
local, not publicly accessible) - Consent logs record IP addresses for audit trail compliance
- The cooling-off period prevents accidental data loss
- All GDPR operations are logged with metadata for compliance audits
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.
Credits
Support
- Issues
- Discussions
- Email: rylxes@gmail.com
rylxes/laravel-gdpr 适用场景与选型建议
rylxes/laravel-gdpr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「privacy」 「consent」 「data-protection」 「gdpr」 「data-export」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rylxes/laravel-gdpr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rylxes/laravel-gdpr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rylxes/laravel-gdpr 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Make TYPO3 more compatible to GDPR
Add a configurable cookie consent banner to the website.
Strips potentially identifying information from outbound requests to the WordPress.org API
Use Klaro! Consent Manager in Contao CMS
This bundle contains functionality concerning privacy and the European Union's "General Data Protection Regulation" (GDPR, in German: "Datenschutz-Grundverordnung", DSGVO).
Symfony 8 bundle for GDPR/DSGVO cookie consent with Google Consent Mode v2, Twig components, Stimulus.js, and AssetMapper. Supports cookie, Doctrine, or combined storage. Includes YouTube, Vimeo, Google Maps embed components.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 43
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-08