PHPackages                             lara-pack/model-history - 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. lara-pack/model-history

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

lara-pack/model-history
=======================

Model History

v1.0.3(3w ago)044MITPHPPHP ^8.2

Since Aug 26Pushed 3w agoCompare

[ Source](https://github.com/bhagaskara/lara-pack-model-history)[ Packagist](https://packagist.org/packages/lara-pack/model-history)[ RSS](/packages/lara-pack-model-history/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (5)Used By (0)

Laravel Model History
=====================

[](#laravel-model-history)

A simple yet powerful Laravel package to track every change in your Eloquent models. This package automatically manages history tables and tracks who made the changes and from which URL.

Features
--------

[](#features)

- **Automatic Change Tracking**: Log `created`, `updated`, and `deleted` events.
- **Dynamic History Tables**: Generate and synchronize history tables based on your original models.
- **User Auditing**: Track which user performed the action (`recorded_by`).
- **Contextual Tracking**: Store the URL where the action occurred (`recorded_url`).
- **Automated Metadata**: Manage `created_by`, `updated_by`, and `deleted_by` fields automatically.
- **Bulk Injection**: Commands to inject traits into all your models at once.
- **Easy Cleanup**: Built-in command to prune old history records.

Requirements
------------

[](#requirements)

- **PHP**: ^8.2
- **Laravel**: ^10.0 or ^11.0

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

[](#installation)

You can install the package via composer:

```
composer require lara-pack/model-history
```

### Local Installation (Development)

[](#local-installation-development)

If you are developing locally and haven't published the package yet, you can add it to your `composer.json` using a path repository:

```
"repositories": [
    {
        "type": "path",
        "url": "../path/to/lara-pack-model-history"
    }
],
"require": {
    "lara-pack/model-history": "dev-main"
}
```

Then run:

```
composer update
```

Setup
-----

[](#setup)

### Commands

[](#commands)

The package provides several artisan commands to simplify the setup:

#### 1. Sync History Tables

[](#1-sync-history-tables)

This command scans your models and generates migrations for your history tables. History tables are prefixed with `_history_`.

```
php artisan lara-pack:sync-history
```

Then run the migration command to apply the changes:

```
php artisan migrate
```

*Migrations will be created in `database/migrations/histories/Y_m_d/` and are automatically loaded by the package.*

#### 2. Bulk Inject Traits

[](#2-bulk-inject-traits)

Inject the `HasHistory` or `HasCompleteHistory` traits into all models within a directory (default: `app/Models`).

```
# To track changes (creates _history_ tables data)
php artisan lara-pack:inject-has-history

# To add metadata (created_by, updated_by, deleted_by)
php artisan lara-pack:inject-has-complete-history
```

### Manual Usage

[](#manual-usage)

#### Tracking Changes

[](#tracking-changes)

Add the `HasHistory` trait to any model you want to track:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use LaraPack\ModelHistory\Traits\HasHistory;

class Post extends Model
{
    use HasHistory;
}
```

#### Tracking Metadata (Created By, etc.)

[](#tracking-metadata-created-by-etc)

Add the `HasCompleteHistory` trait to manage auditing fields:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use LaraPack\ModelHistory\Traits\HasCompleteHistory;

class Post extends Model
{
    use HasCompleteHistory;
}
```

*Note: For `HasCompleteHistory`, your migration should include the necessary columns. You can use the provided Blueprint macro:*

```
Schema::create('posts', function (Blueprint $table) {
    $table->id();
    // ...
    $table->completeHistory(); // Adds timestamps, softDeletes, and audit columns
});
```

Management
----------

[](#management)

### Cleaning History

[](#cleaning-history)

If your history tables grow too large, you can clean them up by date:

```
# Clean records older than 2025-01-01
php artisan lara-pack:clean-history 2025-01-01

# Clean a specific table
php artisan lara-pack:clean-history 2025-01-01 --table=posts

# Force deletion without confirmation
php artisan lara-pack:clean-history 2025-01-01 --force
```

Database Schema
---------------

[](#database-schema)

The history tables (`_history_tablename`) will contain all columns from the original table plus:

- `recorded_at`: Timestamp of the action.
- `recorded_by`: ID of the user who performed the action.
- `recorded_action`: The action performed (`created`, `updated`, `deleted`).
- `recorded_url`: The URL context of the action.

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance95

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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 ~96 days

Total

4

Last Release

21d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24548806?v=4)[bhagaskara](/maintainers/bhagaskara)[@bhagaskara](https://github.com/bhagaskara)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/lara-pack-model-history/health.svg)

```
[![Health](https://phpackages.com/badges/lara-pack-model-history/health.svg)](https://phpackages.com/packages/lara-pack-model-history)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.9M11.7k](/packages/illuminate-database)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8465.5M96](/packages/laravel-doctrine-orm)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[lemaur/eloquent-publishing

218.1k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

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