All ModelScribe drivers — built-in or custom — must implementDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/HypathStack/model-scribe/llms.txt
Use this file to discover all available pages before exploring further.
HypathBel\ModelScribe\Contracts\DriverInterface. This two-method contract keeps the core package decoupled from any particular storage or transport layer, and makes custom drivers straightforward to write and test.
Methods
log(LogEntry $entry): void
Persist or dispatch a single audit log entry to the driver’s target destination.An immutable
The
LogEntry DTO (value object) carrying all audit data for this event. The DTO exposes the following readonly properties:| Property | Type | Description |
|---|---|---|
$event | ScribeEvent | The event type enum case |
$logName | string | Routing / grouping key |
$description | ?string | Human-readable description |
$subject | ?Model | The audited Eloquent model |
$causer | ?Model | The actor Eloquent model |
$properties | array | ['old' => [...], 'attributes' => [...]] |
$tags | array | String tags |
$url | ?string | Request URL |
$ipAddress | ?string | Client IP address |
$userAgent | ?string | Client User-Agent string |
$batchUuid | string | Auto-generated UUID grouping related entries |
LogEntry also exposes a withLogName(string $logName): self method that returns a new instance with a different log name — used internally by the StackDriver to fan entries out to sub-drivers.A
LogEntry is constructed once by ModelScribe::log() or the observer and then handed to the driver. Because it is readonly, drivers must not attempt to modify it. If a driver needs a modified copy (e.g. a different logName), use $entry->withLogName('other').prune(): int
Delete stale records from the driver’s backing store according to its configured retention policy. Returns the count of records removed as anint. Drivers that do not manage persistent state (for example, a webhook or queue driver that dispatches and forgets) should return 0.
prune() is called by ModelScribe::prune(?string $driver = null): int. The DriverInterface does not receive the driver name or any configuration at prune-time — each driver should read its own retention configuration (e.g. config('model-scribe.drivers.database.prune_after_days')) in its constructor or in the prune() implementation itself.Built-in Drivers
Three driver classes ship with ModelScribe, all in theHypathBel\ModelScribe\Drivers namespace:
| Class | Driver key | Description |
|---|---|---|
DatabaseDriver | 'database' | Writes entries to an Eloquent-managed SQL table |
FileDriver | 'file' | Appends JSON-encoded entries to a log file |
StackDriver | 'stack' | Fan-out wrapper; delegates to multiple sub-drivers |
DriverManager
TheDriverManager class resolves, caches, and creates driver instances. It is accessed via ModelScribe::getDriverManager().
driver(?string $name = null): DriverInterface
Resolves a driver by name, returning a cached instance on repeat calls. When$name is null, the global default from config('model-scribe.default') is used.
extend(string callback): static
Register a factory closure for a custom driver name. The closure receives the driver’s configuration array and theDriverManager instance, and must return a DriverInterface implementation. Call this in a ServiceProvider::boot() method before any logging occurs.
flush(): void
Clears the internal cache of resolved driver instances. All subsequent calls todriver() will re-instantiate from configuration. Primarily useful in test suites where you need a clean driver state between test cases.
Writing a Custom Driver
ImplementDriverInterface and register the class via extend(). The full pattern from contract to configuration looks like this:
1. Create the driver class
config/model-scribe.php