bhhaskin / laravel-audit
Audit trail package for Laravel applications with UUID support.
Installs: 1
Dependents: 0
Suggesters: 1
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/bhhaskin/laravel-audit
Requires
- php: ^8.1
- illuminate/database: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- phpunit/phpunit: ^10.5
README
Lightweight audit trail package for Laravel applications.
Features
- Records
created,updated,deleted, andrestoredevents for any model. - Stores both numeric primary keys and UUIDs for audits, auditable models, and users.
- Captures before/after state, request metadata, and user attribution.
- Ships with ready-to-run migrations plus publishable stubs and configuration.
Installation
composer require bhhaskin/laravel-audit
Laravel auto-discovers the service provider. For older versions add LaravelAudit\AuditServiceProvider::class to the providers array in config/app.php.
Publish Assets
php artisan vendor:publish --provider="LaravelAudit\AuditServiceProvider" --tag=laravel-audit-config php artisan vendor:publish --provider="LaravelAudit\AuditServiceProvider" --tag=laravel-audit-migrations
Run the migration:
php artisan migrate
Usage
- Add the
Auditabletrait to any Eloquent model that you want to track. - Ensure the model has a
uuidcolumn populated via the includedHasAuditUuidtrait or your own logic.
use Illuminate\Database\Eloquent\Model; use LaravelAudit\Traits\Auditable; use LaravelAudit\Traits\HasAuditUuid; class Post extends Model { use HasAuditUuid; use Auditable; }
Audits are exposed through the audits() relationship:
$post = Post::first(); foreach ($post->audits as $audit) { echo $audit->uuid; // Frontend-friendly identifier }
Configuration
Published configuration (config/audit.php) lets you:
- Enable/disable the logger or specific events.
- Ignore fields such as timestamps when diffing changes.
- Add default metadata and provide a custom user resolver.
The default user resolver defers to Laravel's auth() helper. Implement a custom resolver by binding a callable class and updating user_resolver in the config.
Events
Two framework events are fired for each audit lifecycle:
LaravelAudit\Events\AuditRecording(before persistence) exposes the proposed payload for last-minute tweaks.LaravelAudit\Events\AuditRecorded(after persistence) includes the savedAuditmodel instance.
Listen for these events to trigger notifications, broadcast changes, or enrich metadata.
License
MIT © Bryan
Testing
composer install
composer test