laravel-lgpd-audit-log maintained by jeffersongoncalves
Laravel LGPD Audit Log

The Brazilian General Data Protection Law (LGPD, Lei 13.709/2018) asks controllers to keep records of their processing (art. 37) and to show the measures they take (art. 6, X). This package keeps an audit trail of who viewed, changed, exported or anonymized personal data, built on laravel-lgpd'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.
lgpd: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-lgpd-audit-log
php artisan vendor:publish --tag="lgpd-audit-log-migrations"
php artisan migrate
Set LGPD_HASH_KEY (see laravel-lgpd). 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\LgpdAuditLog\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-lgpd-dsar or by laravel-lgpd-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']);
LgpdAuditLog::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 lgpd:audit-verify
// routes/console.php
Schedule::command('lgpd: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.