Querying Audit Logs
Query stored events and work with their structured attributes.
Query with Eloquent
Use the package model like any other Eloquent model:
php
use HosmelQ\AuditLog\Models\AuditLog;
$logs = AuditLog::query()
->where('tenant_id', 'org_123')
->where('bucket', 'application')
->latest('occurred_at')
->get();The model uses the configured database connection and table.
Work with stored values
The following columns are cast automatically:
actor_metadata,metadata, andtargetsare arrays.occurred_at,inserted_at, andexpires_atare immutable dates.
Common indexed filters include tenant_id, bucket, event, actor_id, actor_type, correlation_id, and the date columns. The composite index on tenant_id, bucket, occurred_at, and id supports tenant-scoped chronological queries.
Extend the package model when your application needs reusable scopes, relationships, or additional casts. See customizing the audit log model.