aaix / laravel-audit-trails
Lightweight audit-trail package for Laravel — logs created, updated, deleted, restored and force-deleted Eloquent events.
Requires
- php: ^8.3
- illuminate/contracts: >= 11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.18
- orchestra/testbench: ^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-laravel: ^4.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Laravel Audit Trails
A lightweight Laravel audit-log package — one trait, polymorphic by design, soft-delete aware.
Installation
composer require aaix/laravel-audit-trails # Publish the migrations php artisan vendor:publish --tag="audit-trails-migrations" php artisan migrate # Optional php artisan vendor:publish --tag="audit-trails-config"
Quick start
use Aaix\LaravelAuditTrails\Concerns\TracksAuditTrail; class Order extends Model { use TracksAuditTrail; }
Derive columns from the audited record
Each audit row is saved with the audited model attached as a loaded auditable relation, so a creating hook can denormalise a column onto the row without a lookup:
class AuditTrail extends BaseAuditTrail { protected static function booted(): void { static::creating(function (self $trail): void { $trail->tenant_id = $trail->auditable?->tenant_id; }); } }
Don't query by auditable_id instead: deleted fires after the DELETE, so for a model without SoftDeletes the record is already gone and a NOT NULL column fails the insert. The attached instance works for every action, deletes included.
Documentation
Full documentation: jonaaix.github.io/laravel-audit-trails
License
MIT — see LICENSE.md.