jeffersongoncalves / laravel-gdpr-audit-log
GDPR accountability for Laravel (Art. 5(2)): tamper-evident, hash-chained log of who viewed, changed, exported or erased personal data.
Package info
github.com/jeffersongoncalves/laravel-gdpr-audit-log
pkg:composer/jeffersongoncalves/laravel-gdpr-audit-log
Requires
- php: ^8.2
- illuminate/console: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- jeffersongoncalves/laravel-gdpr: ^1.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- jeffersongoncalves/pest-plugin-database-migrations: ^1.0
- larastan/larastan: ^3.0
- laravel/pint: ^1.24
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The EU General Data Protection Regulation (GDPR) makes the controller responsible for, and able to demonstrate, compliance (accountability, Art. 5(2)), and asks for measures that ensure the security of processing (Art. 32). This package keeps an audit trail of who viewed, changed, exported or anonymized personal data, built on laravel-gdpr's #[PersonalData] declarations.
- Column names, never values: the log itself doesn't copy the data it protects.
- Append-only and hash-chained: each entry carries an HMAC of the previous one.
gdpr:audit-verifytells you if an entry was altered, removed from the middle or inserted. - Automatic where Eloquent can see it: changes to personal data columns, deletions, and every anonymization (DSAR erasure, retention).
This package gives you tooling. It does not make you compliant on its own.
Installation
composer require jeffersongoncalves/laravel-gdpr-audit-log
php artisan vendor:publish --tag="gdpr-audit-log-migrations"
php artisan migrate
Set GDPR_HASH_KEY (see laravel-gdpr). The chain falls back to APP_KEY, and rotating the key makes older entries fail verification.
Usage
Add the trait to the models that hold personal data:
use JeffersonGoncalves\GdprAuditLog\Concerns\AuditsPersonalData; #[PersonalData('email', anonymize: AnonymizeStrategy::Hash)] class Customer extends Model implements HasPersonalData { use AuditsPersonalData; use InteractsWithPersonalData; }
- Updating a declared column logs
updatedwith the column names. Other columns are ignored. - Deleting the model logs
deleted. anonymizePersonalData(), called directly, by laravel-gdpr-dsar or by laravel-gdpr-retention, logsanonymized. That save also logsupdatedfirst.
Eloquent can't tell when data is read, so log access where you show it:
$customer->auditAccess('Support ticket #42'); // all declared columns $customer->auditAccess('Billing', ['email']); GdprAuditLog::record('exported', $customer, ['email'], 'Answer a DSAR', ['ticket' => 42]);
The actor is the authenticated user unless you pass actor:. The IP address and user agent of the request are stored too (store_request). They are personal data, so they stay out of the hash chain and can be anonymized without breaking it.
Verifying
php artisan gdpr:audit-verify
// routes/console.php Schedule::command('gdpr:audit-verify')->daily();
The oldest entry you kept is trusted as the start of the chain, so deleting old entries from the start keeps the rest verifiable. A gap in the middle does not.
Testing
composer test
Changelog
See CHANGELOG.
License
The MIT License (MIT). See License File.
