Skip to content

Model auditing ​

php
use Rembon\LaravelAuditor\Traits\Auditable;

class Post extends Model
{
    use Auditable;

    // All optional:
    protected array $auditExclude = ['view_count'];          // never recorded
    protected array $auditEvents = ['updated', 'deleted'];   // default: config('auditor.models.events')
    protected bool $auditRetrieved = false;                  // don't track reads of this model
}

What is stored ​

Eventold_valuesnew_values
created—all attributes
updatedoriginal values of the changed attributesthe changed attributes
deletedall attributessoft deletes: deleted_at
restored, force_deletedas aboveas above
  • An update that only touches excluded attributes (e.g. touch() with updated_at excluded) is not recorded.
  • JSON columns are stored decoded; dates as they are stored.
  • $hidden attributes and encrypted casts are redacted — see Privacy.

Reading the history ​

php
$post->audits;   // ModelChange collection, newest first

use Rembon\LaravelAuditor\Models\ModelChange;

ModelChange::query()
    ->causedBy($user)
    ->since(now()->subWeek())
    ->forModel('post', $post->id)
    ->get();

$change->changedAttributes();   // ['title', 'body']
$change->entry;                 // the request / job / command

Pausing auditing ​

php
Auditor::withoutAuditing(fn () => $post->update(['views' => $post->views + 1]));

Nested calls are safe and the state is restored even when the callback throws.

Limitations ​

Mass updates and deletes through the query builder, insert(), upsert() and pivot attach() / detach() without a custom pivot model do not fire Eloquent events, so they are not recorded as model changes. The entry itself (the request) is still recorded.

Released under the MIT License.