PHPackages                             antonrom00/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. antonrom00/laravel-model-changes-history

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

antonrom00/laravel-model-changes-history
========================================

Model changes history for laravel

5320.5k↓26.7%4[1 issues](https://github.com/Antonrom00/laravel-model-changes-history/issues)PHP

Since Nov 4Pushed 4y ago2 watchersCompare

[ Source](https://github.com/Antonrom00/laravel-model-changes-history)[ Packagist](https://packagist.org/packages/antonrom00/laravel-model-changes-history)[ RSS](/packages/antonrom00-laravel-model-changes-history/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

antonrom00/laravel-model-changes-history
========================================

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

Records the changes history made to an eloquent model.

[![Total Downloads](https://camo.githubusercontent.com/748335c16866e4e9aac1e60792254f02ab7ec0fd99aa48dc138f99198cf8a7ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e746f6e726f6d30302f6c61726176656c2d6d6f64656c2d6368616e6765732d686973746f72792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/antonrom00/laravel-model-changes-history)[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=P58FVTP9QTTEW&source=url)

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

[](#quick-start)

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

```
composer require antonrom00/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 antonrom00/laravel-model-changes-history
```

The package is auto discovered.

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

```
php artisan vendor:publish --provider="Antonrom\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="Antonrom\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
```

**Explore the [config](https://github.com/Antonrom00/laravel-model-changes-history/blob/master/publishable/config/model_changes_history.php)for more detailed library setup.**

Usage
-----

[](#usage)

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

```
use Antonrom\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();

Antonrom\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 => Antonrom\ModelChangesHistory\Models\Change {...}
    1 => Antonrom\ModelChangesHistory\Models\Change {...}
    2 => Antonrom\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 Antonrom\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 Antonrom\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();
}
```

Donation
--------

[](#donation)

If this project help you reduce time to develop, you can buy me a cup of coffee [![buy_me_a_coffee](https://camo.githubusercontent.com/05c9e24ee25944de3cb8aa12b3429a2ee038e7a053beacaa446be8b5114448ae/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f626d632d6e65772d62746e2d6c6f676f2e737667)](https://www.buymeacoffee.com/antonrom)=)

[![paypal](https://camo.githubusercontent.com/e1ff554a09e8e92bef25abc553ff05b88f45afd695877cf12f3a46558ef65b2e/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e61746543435f4c472e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=P58FVTP9QTTEW&source=url)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 97.1% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/95068f206e09794880f3df74cdfd8dff90a51351586f8d12d60c3e4b3c175c21?d=identicon)[Antonrom00](/maintainers/Antonrom00)

---

Top Contributors

[![Antonrom00](https://avatars.githubusercontent.com/u/34814171?v=4)](https://github.com/Antonrom00 "Antonrom00 (34 commits)")[![aburakovskiy](https://avatars.githubusercontent.com/u/1153385?v=4)](https://github.com/aburakovskiy "aburakovskiy (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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