PHPackages                             oluokunkabiru/laravel-audit-log-trail - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. oluokunkabiru/laravel-audit-log-trail

ActiveLibrary[Database &amp; ORM](/categories/database)

oluokunkabiru/laravel-audit-log-trail
=====================================

A robust, diff-aware audit trail package for Laravel Eloquent models.

v2.1.1(2mo ago)00MITPHPPHP ^8.2

Since Apr 3Pushed 2mo agoCompare

[ Source](https://github.com/oluokunkabiru/laravel-audit-log-trail)[ Packagist](https://packagist.org/packages/oluokunkabiru/laravel-audit-log-trail)[ RSS](/packages/oluokunkabiru-laravel-audit-log-trail/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (16)Versions (6)Used By (0)

laravel-audit-trail
===================

[](#laravel-audit-trail)

A fluent, diff-aware audit trail for Eloquent models. Logs exactly what changed, who changed it, and when — with multi-tenant support, a swappable driver system, and a clean suppression API.

Installation
------------

[](#installation)

```
composer require oluokunkabiru/laravel-audit-log-trail
```

Publish and run the migration:

```
php artisan vendor:publish --tag=audit-migrations
php artisan migrate
```

Optionally publish the config:

```
php artisan vendor:publish --tag=audit-config
```

Quick start
-----------

[](#quick-start)

Add the `HasAuditTrail` trait to any Eloquent model:

```
use Oluokunkabiru\AuditTrail\Traits\HasAuditTrail;

class User extends Model
{
    use HasAuditTrail;
}
```

That's it. Every `created`, `updated`, `deleted`, and `restored` event is now logged automatically.

Control Dashboard
-----------------

[](#control-dashboard)

The package comes with a beautiful, Livewire-powered control dashboard out of the box! Access the dashboard at `/audit-trail` in your browser to manage your audit logs.

Features available from the Dashboard include:

- **Discover Models**: Automatically detect and list all Eloquent models in your project.
- **Enable/Disable Tracking**: Instantly inject or remove the `HasAuditTrail` trait from your PHP models with a single click.
- **Global Settings**: Configure the audit storage driver, background queues, and pruning policies directly from the UI natively connecting back to your `.env` file.

*Requires Livewire 3.*

Controlling which fields are logged
-----------------------------------

[](#controlling-which-fields-are-logged)

```
class User extends Model
{
    use HasAuditTrail;

    // Only log these fields
    protected array $auditInclude = ['name', 'email', 'role'];

    // Or: exclude specific fields (stacks with global_exclude in config)
    protected array $auditExclude = ['api_token', 'two_factor_secret'];
}
```

Querying audit logs
-------------------

[](#querying-audit-logs)

```
use Oluokunkabiru\AuditTrail\Models\AuditLog;

// All changes to a specific model instance
AuditLog::forModel($user)->latest()->get();

// Filter by event type
AuditLog::forModel($user)->event('updated')->get();

// Who changed the email field?
AuditLog::forModel($user)->forField('email')->get();

// All deletes in the last 7 days
AuditLog::event('deleted')->since(now()->subDays(7))->get();

// By actor
AuditLog::byActor($admin)->today()->get();
```

Via the model relationship:

```
$user->auditLogs()->latest()->limit(10)->get();
$user->latestAudit;
```

Suppression
-----------

[](#suppression)

```
use Oluokunkabiru\AuditTrail\Facades\Auditor;

// Suppress all logging inside the callback
Auditor::suppress(function () {
    User::factory()->count(1000)->create();
});

// Suppress on a specific model instance
$user->withoutAudit(fn() => $user->update(['name' => 'Silent Bob']));
```

Custom events
-------------

[](#custom-events)

```
Auditor::log($user, 'password_reset', before: ['method' => 'email']);
Auditor::log($order, 'status_changed', before: ['status' => 'pending'], after: ['status' => 'paid']);
```

Multi-tenancy
-------------

[](#multi-tenancy)

In `config/audit.php`:

```
'tenant_resolver' => fn() => auth()->user()?->organization_id,
```

Query scoped to a tenant:

```
AuditLog::forTenant($tenantId)->latest()->get();
```

Async writes (recommended for production)
-----------------------------------------

[](#async-writes-recommended-for-production)

```
AUDIT_QUEUE_ENABLED=true
AUDIT_QUEUE_CONNECTION=redis
AUDIT_QUEUE_NAME=audits
```

Pruning old logs
----------------

[](#pruning-old-logs)

```
# Delete logs older than 365 days (or your configured retention)
php artisan audit:prune

# Override days via option
php artisan audit:prune --days=90
```

Schedule it in `routes/console.php`:

```
Schedule::command('audit:prune')->daily();
```

Configuration reference
-----------------------

[](#configuration-reference)

```
// config/audit.php
return [
    'driver'          => 'database',
    'table'           => 'audit_logs',
    'queue'           => ['enabled' => false, 'connection' => null, 'queue_name' => 'audits'],
    'tenant_resolver' => null,
    'actor_resolver'  => null,
    'prune'           => ['keep_days' => 365],
    'global_exclude'  => ['password', 'remember_token'],
    'metadata'        => ['capture_url' => true, 'capture_ip' => true, 'capture_user_agent' => false],
];
```

Custom drivers
--------------

[](#custom-drivers)

Implement the `AuditDriver` contract and bind it in a service provider:

```
use Oluokunkabiru\AuditTrail\Drivers\Contracts\AuditDriver;

class ElasticsearchAuditDriver implements AuditDriver
{
    public function log(AuditEntry $entry): void { /* ... */ }
    public function prune(int $keepDays): int { /* ... */ }
}

// In AppServiceProvider::register():
$this->app->bind(AuditDriver::class, ElasticsearchAuditDriver::class);
```

Listening to audit events
-------------------------

[](#listening-to-audit-events)

```
use Oluokunkabiru\AuditTrail\Events\AuditLogged;

Event::listen(AuditLogged::class, function (AuditLogged $event) {
    // $event->entry is an AuditEntry value object
    logger()->info('Audit recorded', $event->entry->toArray());
});
```

Running tests
-------------

[](#running-tests)

```
composer test
```

License
-------

[](#license)

MIT

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance83

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

87d ago

Major Versions

v1.0.1 → v2.0.02026-04-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/94fd074663fdc66b70cd016c3ace6abf367180c148532aa142cc4359543ae753?d=identicon)[devvboy](/maintainers/devvboy)

---

Top Contributors

[![oluokunkabiru](https://avatars.githubusercontent.com/u/47401341?v=4)](https://github.com/oluokunkabiru "oluokunkabiru (6 commits)")

---

Tags

logdifflaraveleloquentAudithistorytrail

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/oluokunkabiru-laravel-audit-log-trail/health.svg)

```
[![Health](https://phpackages.com/badges/oluokunkabiru-laravel-audit-log-trail/health.svg)](https://phpackages.com/packages/oluokunkabiru-laravel-audit-log-trail)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k36.8M157](/packages/owen-it-laravel-auditing)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[watson/validating

Eloquent model validating trait.

9803.5M54](/packages/watson-validating)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
