Documentation 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.
HasAuditLog is a PHP trait in the HypathBel\ModelScribe\Traits namespace. Add it to any Eloquent model to enable automatic audit logging. Once mixed in, the trait registers ModelScribeObserver during model booting and exposes a set of configurable properties that control which events, attributes, driver, and tags are used for that model’s audit entries.
Properties
Override any of the following protected properties on your model to customise how audit logging behaves for that class.The Eloquent events that ModelScribe will capture for this model. Valid values are
'created', 'updated', 'deleted', and 'restored'. The 'retrieved' event is recognised by the ScribeEvent enum but is not included here by default due to the volume it can produce.Per-event attribute allowlists that restrict which model attributes are captured in a log entry. When this property is empty (the default), all changed attributes are recorded.The value can take two forms:
- Per-event map — keys are event names, values are string arrays or
'*'(capture all). - Flat array — numeric keys; the same list is applied to every event.
Override the globally-configured default driver for this model. When
null, the package default (defined in config('model-scribe.default')) is used. Set to a named driver key to route this model’s logs elsewhere.A routing key stored in the
log_name column of every entry produced by this model. Use this to segment logs by domain area (e.g. 'invoices', 'orders') and filter them with the ScribeLog::inLog() scope.String tags attached to every log entry created from this model. Tags are stored in the
tags JSON column and can be used for free-form filtering downstream.Methods
Boot
Static boot method called automatically by Laravel’s model booting mechanism. It registers
ModelScribeObserver as an Eloquent observer on the model class via static::observe(ModelScribeObserver::class). You do not need to call this method yourself.Accessors
These methods are called byModelScribeObserver at runtime to read the model’s audit configuration. You can also call them directly if you need to inspect a model’s audit settings programmatically.
Returns the value of
$auditEvents — the list of Eloquent event names that will trigger an audit log entry for this model.Returns the value of
$auditDriver. A null return signals the observer to fall back to the package’s globally-configured default driver.Returns the value of
$auditLogName, which is written to the log_name column of every audit entry produced by this model.Returns the value of
$auditTags — the string tags merged into every log entry produced by this model.Returns the attribute allowlist for the given event name, or
null if all attributes should be captured.Resolution logic:- If
$auditAttributesis empty → returnnull(capture everything). - If
$auditAttributesis a flat array (numeric key at index0) → return it as-is for every event. - Otherwise, look up
$auditAttributes[$event]. If the value is'*'or the key is absent → returnnull. Otherwise cast to array and return.
$auditAttributes value | Return for a given event |
|---|---|
[] | null |
['amount', 'status'] (flat) | ['amount', 'status'] |
['updated' => ['amount']], event 'updated' | ['amount'] |
['updated' => ['amount']], event 'created' | null |
['updated' => '*'] | null |
Full Usage Example
The
bootHasAuditLog() method is invoked automatically by Laravel — you never need to call Invoice::bootHasAuditLog() yourself. Laravel discovers all boot{TraitName}() methods on a model and calls them during Model::boot().