Activity Log
The Activity Log mode (HasActivityLog) is a lightweight way to track changes to your Eloquent models. It records the same events and data as the full Audit Trail, but without the cryptographic hash chain — hash and prev_hash are stored as null.
When to Use Activity Log
Use HasActivityLog when you need to track what changed and who changed it, but don't need cryptographic proof of integrity. Common use cases:
- User activity tracking — who did what, when
- Internal analytics — change frequency, usage patterns
- Debugging — trace down when and how a record changed
- General compliance — where tamper evidence is not required
If you need tamper-evident, verifiable audit records, use HasAuditTrail instead.
Usage
Add the HasActivityLog trait and implement the Auditable interface:
use GrayMatter\AuditChain\Concerns\HasActivityLog; use GrayMatter\AuditChain\Contracts\Auditable; class Post extends Model implements Auditable { use HasActivityLog; }
That's it. AuditChain will now automatically log created, updated, and deleted events for your model.
What Gets Recorded
Each audit log entry captures:
- Event type —
created,updated,deleted(plusrestored,forceDeletedfor SoftDeletes) - Old and new values — the fields that changed
- User — the authenticated user who made the change
- IP address and user agent
- Timestamp — in UTC
$post = Post::create(['title' => 'Hello World', 'body' => '...']); $post->auditLogs->first(); // event: 'created' // new_values: ['title' => 'Hello World', 'body' => '...'] // hash: null // prev_hash: null
Custom Events
Record business-level events that go beyond CRUD:
$post->audit('published'); $post->audit('featured', oldValues: ['featured' => false], newValues: ['featured' => true], );
Querying Audit Logs
Access a model's audit history through the auditLogs relationship:
$post->auditLogs; $post->auditLogs()->where('event', 'updated')->latest('created_at')->get();
Upgrading to Audit Trail
If your requirements change, switching from HasActivityLog to HasAuditTrail is a one-line change:
- use HasActivityLog; + use HasAuditTrail;
Existing activity log entries (with null hashes) will remain in the database. The hash chain starts fresh from the first entry recorded with HasAuditTrail — verification only checks entries where hash is not null.