PHPackages                             davidiwezulu/audittrail - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. davidiwezulu/audittrail

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

davidiwezulu/audittrail
=======================

Laravel package that automatically tracks changes to Eloquent models

v1.0.0(1y ago)14MITPHPPHP ^8.0

Since Sep 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/davidiwezulu/audit-trail)[ Packagist](https://packagist.org/packages/davidiwezulu/audittrail)[ RSS](/packages/davidiwezulu-audittrail/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Davidiwezulu/AuditTrail
=======================

[](#davidiwezuluaudittrail)

[![Latest Version on Packagist](https://camo.githubusercontent.com/97bf7f3eea08e62eab2c8943b7bff308e3aa85f3eb950bff1c4ddb63078213e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f44617669646977657a756c752f4175646974547261696c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Davidiwezulu/AuditTrail)[![Total Downloads](https://camo.githubusercontent.com/7c25e3acb16d8d0a78adb725b5b42602a0a3d3d5a0ab645ee1eca5c9b9c1eb34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f44617669646977657a756c752f4175646974547261696c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Davidiwezulu/AuditTrail)[![Build Status](https://camo.githubusercontent.com/8630d6b6909d154d13cae4868ae512796add0fafc8a06567bca67372860f53de/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f44617669646977657a756c752f4175646974547261696c2f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/Davidiwezulu/AuditTrail/actions)[![License](https://camo.githubusercontent.com/4744472ca9a90ee5f2ddd338f9b8f1fed8953da3c37e91a188e90d5118e06c49/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f44617669646977657a756c752f4175646974547261696c2e7376673f7374796c653d666c61742d737175617265)](https://github.com/Davidiwezulu/AuditTrail/blob/main/LICENSE.md)

[![Laravel Version](https://camo.githubusercontent.com/0ad008dde10073d5ea02a013998cdbdb588936dfe911d0dbc1910c7bfd64dc6a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e782d6f72616e67653f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)](https://camo.githubusercontent.com/0ad008dde10073d5ea02a013998cdbdb588936dfe911d0dbc1910c7bfd64dc6a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d392e782d6f72616e67653f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c)

Overview
--------

[](#overview)

**Davidiwezulu/AuditTrail** is a Laravel package that automatically tracks changes to Eloquent models, providing:

- **Versioning**: Each modification to a model is stored as a new version.
- **Rollback Capabilities**: Easily revert any model to a previous version.
- **Detailed Logs**: Record what was changed, when, and by whom (with user tracking).

This package is designed for applications that require comprehensive audit trails, ensuring data integrity and easy recovery of historical data.

Features
--------

[](#features)

- Automatically tracks `created`, `updated`, and `deleted` events for any Eloquent model.
- Maintains a log of both the old and new values of changed attributes.
- Supports rollback to any previous version of a model.
- Logs changes made by authenticated users.
- Detailed audit history accessible via relationships.

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

[](#installation)

### Requirements

[](#requirements)

- Laravel 9.x or newer
- PHP 8.0 or newer

### Step 1: Install via Composer

[](#step-1-install-via-composer)

Run the following command to install the package:

```
composer require Davidiwezulu/audittrail
```

### Step 2: Publish and Run Migrations

[](#step-2-publish-and-run-migrations)

Publish the migration file for the audit\_trails table:

```
php artisan vendor:publish --tag=audittrail-migrations
```

Run the migrations:

```
php artisan migrate
```

Configuration
-------------

[](#configuration)

This package comes with default settings, but you can publish the configuration file if you'd like to customize the package further:

```
php artisan vendor:publish --provider="Davidiwezulu\AuditTrail\AuditTrailServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

### Step 1: Use the Auditable Trait in Your Model

[](#step-1-use-the-auditable-trait-in-your-model)

To enable audit tracking for a model, use the Auditable trait in your Eloquent model:

```
auditTrails;

foreach ($auditTrails as $audit) {
    echo $audit->event . ': ' . json_encode($audit->new_values) . PHP_EOL;
}
```

### Step 3: Rollback to a Previous Version

[](#step-3-rollback-to-a-previous-version)

To rollback a model to a previous version, you can use the rollbackTo() method:

```
$post = Post::find(1);
$auditTrailId = 5; // The ID of the audit trail entry to rollback to
$post->rollbackTo($auditTrailId);
```

The model will be restored to the old values recorded in the selected audit trail.

Events
------

[](#events)

By default, the package listens to the created, updated, and deleted events. You can modify which events are tracked by overriding the getAuditEvents method in your model:

```
protected static function getAuditEvents()
{
    return ['created', 'updated']; // Only log created and updated events
}
```

Testing
-------

[](#testing)

This package comes with unit tests to ensure functionality. To run the tests, use the following command within the package itself:

```
vendor/bin/phpunit
```

Test Scenarios
--------------

[](#test-scenarios)

### 1. Model Changes:

[](#1-model-changes)

Verify that `created`, `updated`, and `deleted` events generate appropriate audit logs.

### 2. Rollback:

[](#2-rollback)

Ensure models can be reverted to previous versions using the rollback feature.

### 3. Relationships:

[](#3-relationships)

Confirm that the audit trail's morph relationships are correctly established between auditable models and users.

---

Contribution Guidelines
-----------------------

[](#contribution-guidelines)

If you wish to contribute to this package, please follow these steps:

1. Fork the repository.
2. Create a feature branch: ```
    git checkout -b feature/new-feature
    ```
3. Commit your changes: ```
    git commit -m 'Add new feature'
    ```
4. Push to the branch: ```
    git push origin feature/new-feature
    ```
5. Open a pull request, and provide a description of your changes.

### All contributions must adhere to the following guidelines:

[](#all-contributions-must-adhere-to-the-following-guidelines)

- Ensure code quality by following the Laravel style guide.
- Add unit tests for any new features or bug fixes.
- Update the README with any changes that impact usage.

License
-------

[](#license)

This package is open-source software licensed under the [MIT License](LICENSE).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Unknown

Total

1

Last Release

597d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3697dfced26f3985512f9ab6f068ce20abb9c40a30cc83c8fa69d92db33d649a?d=identicon)[davidiwezulu](/maintainers/davidiwezulu)

---

Top Contributors

[![davidiwezulu](https://avatars.githubusercontent.com/u/35039663?v=4)](https://github.com/davidiwezulu "davidiwezulu (2 commits)")

### Embed Badge

![Health badge](/badges/davidiwezulu-audittrail/health.svg)

```
[![Health](https://phpackages.com/badges/davidiwezulu-audittrail/health.svg)](https://phpackages.com/packages/davidiwezulu-audittrail)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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