PHPackages                             elaborate-code/laravel-eloquent-logs - 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. elaborate-code/laravel-eloquent-logs

Abandoned → [spatie/laravel-activitylog](/?search=spatie%2Flaravel-activitylog)ArchivedLibrary[Database &amp; ORM](/categories/database)

elaborate-code/laravel-eloquent-logs
====================================

A simple way to log changes that occur on Eloquent models

1.1.0(3y ago)19278[4 PRs](https://github.com/elaborate-code/laravel-eloquent-logs/pulls)MITPHPPHP ^8.1

Since Jul 24Pushed 2y agoCompare

[ Source](https://github.com/elaborate-code/laravel-eloquent-logs)[ Packagist](https://packagist.org/packages/elaborate-code/laravel-eloquent-logs)[ Docs](https://github.com/elaborate-code/laravel-eloquent-logs)[ RSS](/packages/elaborate-code-laravel-eloquent-logs/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (12)Versions (7)Used By (0)

laravel-eloquent-logs
=====================

[](#laravel-eloquent-logs)

[![Packagist Version](https://camo.githubusercontent.com/d0d8be7c0e35329d58d8bb64097363eb22a5d71504da5ffdb0a415d6c09348e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c61626f726174652d636f64652f6c61726176656c2d656c6f7175656e742d6c6f67733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/elaborate-code/laravel-eloquent-logs)[![Packagist Downloads (custom server)](https://camo.githubusercontent.com/f05ab96abc10e3e4e54fd359854822d2fde252a3fd3ace634faadb639423e4bf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c61626f726174652d636f64652f6c61726176656c2d656c6f7175656e742d6c6f67733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/elaborate-code/laravel-eloquent-logs)[![GitHub Workflow Status](https://camo.githubusercontent.com/b1904884d5c2f37934e7a7b4a2bd9f4aceb560f9deb3730056d624cda546185d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f656c61626f726174652d636f64652f6c61726176656c2d656c6f7175656e742d6c6f67732f72756e2d74657374733f6c6162656c3d5465737473267374796c653d666f722d7468652d6261646765)](https://github.com/elaborate-code/laravel-eloquent-logs/actions/workflows/run-tests.yml)[![GitHub Workflow Status](https://camo.githubusercontent.com/487edc30b2577d164cb7f611229cf2f7bdec4030022521467af8fa3a6dc22cab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f656c61626f726174652d636f64652f6c61726176656c2d656c6f7175656e742d6c6f67732f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d436f64652532305374796c65267374796c653d666f722d7468652d6261646765)](https://github.com/elaborate-code/laravel-eloquent-logs/actions/workflows/fix-php-code-style-issues.yml)[![maintained](https://camo.githubusercontent.com/652950e93cdb2b41c0c752ae200d6defea506fa6b49a80fc38c349f9757c08cc/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f32303232)](https://camo.githubusercontent.com/652950e93cdb2b41c0c752ae200d6defea506fa6b49a80fc38c349f9757c08cc/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f32303232)[![Production ready](https://camo.githubusercontent.com/bf2af9c8c08732324e3e7b4f7e5aa699d4fd9eb83b3f16ab9062689efaa68df3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50726f64756374696f6e25323072656164792d6e6f2d726564)](https://camo.githubusercontent.com/bf2af9c8c08732324e3e7b4f7e5aa699d4fd9eb83b3f16ab9062689efaa68df3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50726f64756374696f6e25323072656164792d6e6f2d726564)

[![banner](https://camo.githubusercontent.com/acfc1fbda64268d078b7e7e963d306a97c71ed124e192080a0ca9ffddfbf7295/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f456c6f7175656e742532306c6f67732e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d656c61626f726174652d636f64652532466c61726176656c2d656c6f7175656e742d6c6f6773267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d412b73696d706c652b7761792b746f2b6c6f672b6368616e6765732b746861742b6f636375722b6f6e2b456c6f7175656e742b6d6f64656c73266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/acfc1fbda64268d078b7e7e963d306a97c71ed124e192080a0ca9ffddfbf7295/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f456c6f7175656e742532306c6f67732e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d656c61626f726174652d636f64652532466c61726176656c2d656c6f7175656e742d6c6f6773267061747465726e3d63697263756974426f617264267374796c653d7374796c655f31266465736372697074696f6e3d412b73696d706c652b7761792b746f2b6c6f672b6368616e6765732b746861742b6f636375722b6f6e2b456c6f7175656e742b6d6f64656c73266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

Log what happens to your Eloquent models (`created`|`updated`|`deleted`|`soft deleted`|`restored`|`force deleted`) and keep and eye on **who** made the change, **how** and **when**.

This solution is simple to integrate and introduces minimal changes to your project: 1 migration, 1 model, 1 trait, and 1 facade.

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

[](#installation)

Install the package via composer:

```
composer require elaborate-code/laravel-eloquent-logs
```

Publish the migrations:

```
php artisan vendor:publish --tag="eloquent-logs-migrations"
```

Run the migrations:

```
php artisan migrate
```

### Publishing config file \[Optional\]

[](#publishing-config-file-optional)

You can publish the config file with:

```
php artisan vendor:publish --tag="eloquent-logs-config"
```

This is the contents of the published config file:

```
return [
    'logs_model' => \ElaborateCode\EloquentLogs\Models\EloquentLog::class,
    'logs_table' => 'eloquent_logs',

    'user' => \App\Models\User::class,
];
```

That allows you to rename the `logs_table` before running the migrations.

Usage
-----

[](#usage)

Pick an **Eloquent model** that you want to log the changes that happen to it and add the `HasLogs` trait to it.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ExampleModel extends Model
{
    use \ElaborateCode\EloquentLogs\Concerns\HasLogs;
    // ...
}
```

After adding that trait, every change made to the model will be recorded.

Important warning from [Laravel docs](https://laravel.com/docs/9.x/eloquent#events:~:text=When%20issuing%20a%20mass%20update%20or,when%20performing%20mass%20updates%20or%20deletes.)

> When issuing a **mass update or delete** query via Eloquent, the `saved`, `updated`, `deleting`, and `deleted` model events will not be dispatched for the affected models. This is because the models are never actually retrieved when performing mass updates or deletes.

### Retrieving logs

[](#retrieving-logs)

You can load a model's logs using the `eloquentLogs` relationship:

```
$example_model->eloquentLogs;

$example_model->load('eloquentLogs');

App\Models\ExampleModel::with('eloquentLogs')->find($id);
```

And you can query logs directly:

```
// latest 5 logs with affected models
ElaborateCode\EloquentLogs\Models\EloquentLog::with('loggable')->latest()->limit(5)->get()
```

### Grouping queries

[](#grouping-queries)

By default each one model event will result in a query to log the action.

```
$example_model = ExampleModel::create(['name' => 'foo']);

$example_model->update(['name' => 'bar']);

$example_model->delete();

// ⚠️ This will result in 3 queries to insert the 3 events logs into the database
```

You can improve the logging process by using the `CacheEloquentLogQueries` facade

```
use ElaborateCode\EloquentLogs\Facades\CacheEloquentLogQueries;

CacheEloquentLogQueries::start();

$example_model = ExampleModel::create(['name' => 'foo']);

$example_model->update(['name' => 'bar']);

$example_model->delete();

CacheEloquentLogQueries::execute();

// 👍 This will result in 1 query to insert the 3 events logs into the database
```

The facade includes other methods that you wouldn't necessarily need to use:

```
// Stops caching and empties the cache without queries execution
CacheEloquentLogQueries::reset();

// Empties the cache but doesn't stop caching
CacheEloquentLogQueries::flushQueries();

// Stops caching until the reuse of start() and doesn't empty the cache
CacheEloquentLogQueries::suspend();

// Returns a boolean
CacheEloquentLogQueries::isCaching();
```

### Ignoring events

[](#ignoring-events)

You can specify the events to not log on the model instances by listing the events to ignore on `YourModel::$loggableOptions['ignore']`.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ExampleModel extends Model
{
    use \ElaborateCode\EloquentLogs\Concerns\HasLogs;

    public static array $loggableOptions = [
        'ignore' => ['created', 'updated', 'deleted', 'softDeleted', 'forceDeleted', 'restored'],
    ];
    // ...
}
```

### Muting Eloquent events \[Laravel stuff\]

[](#muting-eloquent-events-laravel-stuff)

From seeders:

```
namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    use WithoutModelEvents; // Add this trait

    public function run(): void
    {
        // Silent eloquent queries ...
    }
}
```

Anywhere from your code:

```
\Illuminate\Database\Eloquent\Model::unsetEventDispatcher();

// Silent eloquent queries ...

\Illuminate\Database\Eloquent\Model::setEventDispatcher(app(Dispatcher::class));
// ...
```

Explore the [Eloquent docs](https://laravel.com/docs/9.x/eloquent#muting-events) for more options

Alternative
-----------

[](#alternative)

Among the bajillion packages that Spatie has so graciously bestowed upon the community, you'll find the excellent [laravel-Alternative](https://github.com/spatie/laravel-activitylog) package.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/elaborate-code/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [medilies](https://github.com/elaborate-code)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 81.3% 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 ~4 days

Total

2

Last Release

1383d ago

### Community

Maintainers

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

---

Top Contributors

[![medilies](https://avatars.githubusercontent.com/u/35309918?v=4)](https://github.com/medilies "medilies (61 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")

---

Tags

eloquenteventslaravelloggingpackageloglaraveleloquent

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/elaborate-code-laravel-eloquent-logs/health.svg)

```
[![Health](https://phpackages.com/badges/elaborate-code-laravel-eloquent-logs/health.svg)](https://phpackages.com/packages/elaborate-code-laravel-eloquent-logs)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17649.9k](/packages/lacodix-laravel-model-filter)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[altek/accountant

The auditing &amp; accountability package for Laravel's Eloquent ORM.

92954.3k4](/packages/altek-accountant)[indexzer0/eloquent-filtering

Powerful eloquent filtering

22425.9k3](/packages/indexzer0-eloquent-filtering)

PHPackages © 2026

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