User Agent
AuditChain automatically captures the user agent string from the current HTTP request and stores it on every audit log entry. This helps identify which browser, API client, or device triggered a change.
Automatic Capture
No configuration needed. When an auditable model changes during an HTTP request, the user_agent column is populated from the request headers:
$order->update(['status' => 'shipped']); // Audit log includes: // user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ..."
Console and Queue Context
When changes happen outside an HTTP request — in Artisan commands, queue jobs, or scheduled tasks — the user agent is set to null:
// In an Artisan command or queued job $order->update(['status' => 'processed']); // Audit log: user_agent = null
This makes it easy to distinguish between user-initiated changes and system-initiated changes.
What Gets Captured
The full User-Agent header value is stored as-is. Common examples:
| Source | User Agent |
|---|---|
| Browser | Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ... |
| Mobile app | MyApp/2.1.0 (iOS 17.0; iPhone14,5) |
| API client | GuzzleHttp/7 |
| Artisan / Queue | null |
Querying by User Agent
Find changes made from a specific client:
$order->auditLogs() ->where('user_agent', 'like', '%iPhone%') ->get(); // Or find all system-initiated changes $order->auditLogs() ->whereNull('user_agent') ->get();
IP Address
User agent capture works alongside automatic IP address capture. Both are resolved from the current request and both are null in console context. Together they provide a clear picture of where and how a change originated.