laravel-consent-guard
Laravel package for consent tracking and a tamper-evident audit log.
~/problem
Apps need consent checks and tamper-evident audit logs without rebuilding the mechanism each time. This extracts and generalises privacy-forge's audit log and adds a new consent guard.
A reusable package installed with composer require. It provides a hash-chained audit log for any Eloquent model and a fail-closed consent guard with a cast, middleware and a retention-sweep Artisan command. It is tested against a Laravel and PHP version matrix.
~/highlights
- Audit entry hash is sha256 of the previous hash plus fields, serialised with pg_advisory_xact_lock for concurrent writers.
- Privilege separation through an installable Artisan command using real Postgres GRANT and REVOKE.
- ConsentManager::isGranted() is the single fail-closed choke point, with fault-injection tests for the guarantee.
- Supports Laravel 12 and 13 and PHP 8.2+ through illuminate components; Orchestra Testbench matrix in CI.
- 42 Pest tests with 103 assertions in the run captured in the README; Larastan static analysis runs in CI.
- Installed with composer require into a fresh Laravel 13 app through a local path repository (it is not on Packagist yet); UPGRADE.md and semantic versioning are in place.
~/architecture
- Consent guard → ConsentManager
- ConsentRequired cast, EnsureConsentGranted middleware, retention sweep command.
- ConsentManager → Host database
- Single fail-closed decision point reading ConsentRecord.
- Audit log → Host database
- Eloquent-integrated hash-chained entries.
- Host database
- The consuming application's database. Audit log requires PostgreSQL.
- Service provider → Consent guard, Audit log
- Registers config, migrations and commands in the host app.
~/stack
- PHP 8.2+
- Laravel 12/13
- Eloquent
- PostgreSQL
- Pest
- Larastan
- Orchestra Testbench
~/status
v1.0.0 released 2026-08-23. Not yet published on Packagist; the README says so. MIT.
~/related
- privacy-forge Self-hosted consent, DSAR and data-retention engine for small SaaS teams.