Quickstart
Get audit logging working in your Laravel application in under 5 minutes.
Step 1: Choose Your Mode
AuditChain offers two modes. Pick the one that fits your needs:
| Mode | Trait | Hash Chain | Best For |
|---|---|---|---|
| Activity Log | HasActivityLog |
No | General logging, analytics |
| Audit Trail | HasAuditTrail |
Yes | Compliance, legal, financial |
Step 2: Add the Trait
Activity Log (Light Mode)
Simple activity logging without cryptographic verification:
use GrayMatter\AuditChain\Concerns\HasActivityLog; use GrayMatter\AuditChain\Contracts\Auditable; class Post extends Model implements Auditable { use HasActivityLog; }
Audit Trail (Full Mode)
Immutable audit trail with SHA-256 hash chain:
use GrayMatter\AuditChain\Concerns\HasAuditTrail; use GrayMatter\AuditChain\Contracts\Auditable; class Order extends Model implements Auditable { use HasAuditTrail; }
Step 3: It Just Works
That's it. All create, update, and delete events are now automatically captured:
// All of these are automatically audited $order = Order::create(['status' => 'pending', 'total' => 99.99]); $order->update(['status' => 'shipped']); $order->delete();
Step 4: Query Audit Logs
Every auditable model gets an auditLogs relationship:
// Get all audit logs for this order $order->auditLogs; // Filter by event type $order->auditLogs()->where('event', 'updated')->get();
Step 5: Verify Chain Integrity (Full Mode)
If you're using HasAuditTrail, verify that no one has tampered with your audit logs:
php artisan audit:verify
What's Next?
- Chain Verification — Automate integrity checks
- Custom Events — Record business-level events
- Batch Grouping — Group related operations
- Personal Data Annotation — Annotate personal data fields