Skip to main content
Every LogEntry that ModelScribe writes to a driver carries a batchUuid — a UUID string that is persisted in the batch_uuid column of the log table. By default, each individual Eloquent event (a created, updated, or deleted call) produces its own LogEntry with a freshly generated UUID, so under normal automatic logging each entry is its own batch. The real power of batch_uuid emerges when you want to tie multiple related entries together so you can retrieve all the changes that happened as part of a single logical operation.

How batch_uuid Is Generated

The batch_uuid value is set inside the LogEntry constructor. If no UUID is provided, Str::uuid() is called automatically:
This means every log entry always has a batch_uuid, even when you never think about batching. For automatic observer-driven logs, each event gets its own unique UUID. For manual logs created via ModelScribe::log(), the UUID is likewise generated per call — unless you take deliberate steps to share one across multiple calls (see below).

Querying Entries by Batch UUID

Because batch_uuid is a plain column on the ScribeLog model, you can query it like any other attribute using Eloquent:
Querying by batch_uuid is a practical way to display all changes that occurred during a single HTTP request or background job — for example, building an “undo this operation” feature, or providing a detailed audit trail grouped by the action that triggered it.

Grouping Manual Logs with a Shared Batch UUID

The LogEntry constructor accepts an optional ?string $batchUuid = null parameter. Since ModelScribe::log() creates a LogEntry internally, you can coordinate a shared batch UUID across multiple manual log calls by passing a consistent identifier via the properties array, or by building LogEntry objects directly if you are working at a lower level.
For most manual-logging use cases, the recommended pattern is to generate a UUID once and include it in the properties of each related call so you can group and retrieve the entries together:
You can then retrieve all entries associated with that batch by filtering on the JSON batch_id property:

Querying the Native batch_uuid Column

For automatic observer-driven entries, batch_uuid is always populated from the LogEntry value object. If you are building an integration that constructs LogEntry objects directly and passes them to a driver, you can supply a pre-generated UUID to group them:
Both entries will share the same batch_uuid in the database and can be fetched together: