PHPackages                             isaevdimka/laravel-model-changes-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. [Framework](/categories/framework)
4. /
5. isaevdimka/laravel-model-changes-history

ActiveLibrary[Framework](/categories/framework)

isaevdimka/laravel-model-changes-history
========================================

Model changes history for laravel

1.0(5y ago)012MITPHPPHP &gt;=7.4

Since Feb 1Pushed 5y ago1 watchersCompare

[ Source](https://github.com/IsaevDimka/laravel-model-changes-history)[ Packagist](https://packagist.org/packages/isaevdimka/laravel-model-changes-history)[ Docs](https://github.com/IsaevDimka/laravel-model-changes-history)[ RSS](/packages/isaevdimka-laravel-model-changes-history/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

IsaevDimka/laravel-model-changes-history
========================================

[](#isaevdimkalaravel-model-changes-history)

Records the changes history made to an eloquent model.

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

[](#quick-start)

**Your model must have an `id` field!**

```
composer require isaevdimka/laravel-model-changes-history
```

```
php artisan vendor:publish --tag="model-changes-history"
```

```
php artisan migrate
```

**Note: this library use `database` storage as default.**

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

[](#installation)

```
composer require isaevdimka/laravel-model-changes-history
```

The package is auto discovered.

To change the config, publish it using the following command:

```
php artisan vendor:publish --provider="ModelChangesHistory\Providers\ModelChangesHistoryServiceProvider" --tag="config"
```

You can use three ways for record changes: `'storage' => 'database', 'file' or 'redis'`

If you want to use `database` storage, you must publish the migration file, run the following artisan commands:

```
php artisan vendor:publish --provider="ModelChangesHistory\Providers\ModelChangesHistoryServiceProvider" --tag="migrations"
```

```
php artisan migrate
```

Use this environment to manage library:

```
# Global recorgin model changes history
RECORD_CHANGES_HISTORY=true

# Default storage for recorgin model changes history
MODEL_CHANGES_HISTORY_STORAGE=database
```

Usage
-----

[](#usage)

Add the trait to your model class you want to record changes history for:

```
use ModelChangesHistory\Traits\HasChangesHistory;
use Illuminate\Database\Eloquent\Model;

class TestModel extends Model {
    use HasChangesHistory;

    /**
     * The attributes that are mass assignable.
     * This will also be hidden for changes history.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token'];
}
```

Your model now has a relation to all the changes made:

```
$testModel->latestChange();

ModelChangesHistory\Models\Change {
    ...
    #attributes:  [
        "model_id" => 1
        "model_type" => "App\TestModel"
        "before_changes" => "{...}"
        "after_changes" => "{...}"
        "change_type" => "updated"
        "changes" => "{
            "title": {
                "before": "Some old title",
                "after": "This is the new title"
            },
            "body": {
                "before": "Some old body",
                "after": "This is the new body"
            },
            "password": {
                "before": "[hidden]",
                "after": "[hidden]"
            }
        }"
        "changer_type" =>  "App\User"
        "changer_id" => 1
        "stack_trace" => "{...}"
        "created_at" => "2020-01-21 17:34:31"
    ]
    ...
}
```

#### Getting all changes history:

[](#getting-all-changes-history)

```
$testModel->historyChanges();

Illuminate\Database\Eloquent\Collection {
  #items: array:3 [
    0 => ModelChangesHistory\Models\Change {...}
    1 => ModelChangesHistory\Models\Change {...}
    2 => ModelChangesHistory\Models\Change {...}
    ...
}
```

**If you use `database` storage you can also use morph relations to `Change` model:**

```
$testModel->latestChangeMorph();
$testModel->historyChangesMorph();
```

#### Clearing changes history:

[](#clearing-changes-history)

```
$testModel->clearHistoryChanges();
```

#### Get an independent changes history:

[](#get-an-independent-changes-history)

```
use ModelChangesHistory\Facades\HistoryStorage;
...

$latestChanges = HistoryStorage::getHistoryChanges(); // Return collection of all latest changes
$latestChanges = HistoryStorage::getHistoryChanges($testModel); // Return collection of all latest changes for model

$latestChange = HistoryStorage::getLatestChange(); // Return latest change
$latestChange = HistoryStorage::getLatestChange($testModel); // Return latest change for model

HistoryStorage::deleteHistoryChanges(); // This will delete all history changes
HistoryStorage::deleteHistoryChanges($testModel); // This will delete all history changes for model
```

#### Getting model changer:

[](#getting-model-changer)

```
// Return Authenticatable `changer_type` using HasOne relation to changer_type and changer_id
$changer = $latestChange->changer;
```

##### If you use `database` storage you can use `Change` model as:

[](#if-you-use-database-storage-you-can-use-change-model-as)

```
use ModelChangesHistory\Models\Change;

// Get the updates on the given model, by the given user, in the last 30 days:
Change::query()
    ->whereModel($testModel)
    ->whereChanger($user)
    ->whereType(Change::TYPE_UPDATED)
    ->whereCreatedBetween(now()->subDays(30), now())
    ->get();
```

#### Clearing changes history using console:

[](#clearing-changes-history-using-console)

```
php artisan changes-history:clear
```

You can use it in `Kelner`:

```
protected function schedule(Schedule $schedule)
{
    $schedule->command('changes-history:clear')->monthly();
}
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

1926d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dee94a7ed186095ec72dbe6eaa966ffac25a8a01a1441f96a9758429d14023c5?d=identicon)[IsaevDimka](/maintainers/IsaevDimka)

---

Top Contributors

[![IsaevDimka](https://avatars.githubusercontent.com/u/2106742?v=4)](https://github.com/IsaevDimka "IsaevDimka (1 commits)")

---

Tags

frameworklaravelmodelhistorychanges

### Embed Badge

![Health badge](/badges/isaevdimka-laravel-model-changes-history/health.svg)

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

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[unopim/unopim

UnoPim Laravel PIM

9.4k1.8k](/packages/unopim-unopim)[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3691.5k](/packages/codewithdennis-larament)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)

PHPackages © 2026

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