PHPackages                             cviebrock/eloquent-loggable - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. cviebrock/eloquent-loggable

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

cviebrock/eloquent-loggable
===========================

Easy change logging for your Eloquent models in Laravel 5.

81531[1 issues](https://github.com/cviebrock/eloquent-loggable/issues)PHP

Since Jul 6Pushed 8y ago2 watchersCompare

[ Source](https://github.com/cviebrock/eloquent-loggable)[ Packagist](https://packagist.org/packages/cviebrock/eloquent-loggable)[ RSS](/packages/cviebrock-eloquent-loggable/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Eloquent-Loggable
=================

[](#eloquent-loggable)

Easy way to track changes to your Eloquent models in Laravel 5.

[![Build Status](https://camo.githubusercontent.com/30b3e767fa8f2eed2b0cd9650bd360d18a1f65474e7805caa621ce196f084258/68747470733a2f2f7472617669732d63692e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f676761626c652e7376673f6272616e63683d6d617374657226666f726d61743d666c6174)](https://travis-ci.org/cviebrock/eloquent-loggable)[![Total Downloads](https://camo.githubusercontent.com/d0782f0ee641c0ba7f133156302d6bdad7419c26d35ca6f1c40b69d9cacc168e/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f676761626c652f646f776e6c6f6164733f666f726d61743d666c6174)](https://packagist.org/packages/cviebrock/eloquent-loggable)[![Latest Stable Version](https://camo.githubusercontent.com/8f7e7776ae65b35795935e81e735ac67d6d3b5040bf271efa8f2080f98ebc6f6/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f676761626c652f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/cviebrock/eloquent-loggable)[![Latest Unstable Version](https://camo.githubusercontent.com/fda04661905c51d6ef9beb25720f63fc7b7569c7e2c93fa5eb7b9142f6bf5e2b/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f656c6f7175656e742d6c6f676761626c652f762f756e737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/cviebrock/eloquent-loggable)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/052650b0b2acf34ed15517e99227a118b3aaece6f5a98a96a1069a45f9d1505f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6376696562726f636b2f656c6f7175656e742d6c6f676761626c652f6261646765732f7175616c6974792d73636f72652e706e673f666f726d61743d666c6174)](https://scrutinizer-ci.com/g/cviebrock/eloquent-loggable)[![SensioLabsInsight](https://camo.githubusercontent.com/5058a32c46c8195ffadf9ffda34a99d1fc2ed04407a266937810e72004768c00/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f30623936366531332d366136612d346431372d626365612d3631303337663034636665372f6d696e692e706e67)](https://insight.sensiolabs.com/projects/0b966e13-6a6a-4d17-bcea-61037f04cfe7)[![License: MIT](https://camo.githubusercontent.com/c2bffd81d308ced1cc3b0d66fb0ed453ab478a5e17c988b780f9de986a390ee2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)

- [Installation](#installation)
- [Updating your Eloquent Models](#updating-your-eloquent-models)
- [Usage](#usage)
    - [Change Sets](#change-sets)
    - [Other Query Scopes](#other-query-scopes)
- [Configuration](#configuration)
- [Bugs, Suggestions and Contributions](#bugs-suggestions-and-contributions)
- [Copyright and License](#copyright-and-license)

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

[](#installation)

First, you'll need to install the package via Composer:

```
$ composer require cviebrock/eloquent-loggable
```

Then, update `config/app.php` by adding an entry for the service provider (if you are using Laravel 5.5 with package auto-discovery, you can skip this step):

```
'providers' => [
    // ...
    Cviebrock\EloquentLoggable\ServiceProvider::class,
];
```

Finally, from the command line again, publish the default configuration file:

```
php artisan vendor:publish --provider="Cviebrock\EloquentLoggable\ServiceProvider"
```

Updating your Eloquent Models
-----------------------------

[](#updating-your-eloquent-models)

Your models should use the `Cviebrock\EloquentLoggable\Loggable` trait. This trait provides two methods which can be overloaded in your models:

1. `getLoggableAttributes()` should return an array of all the model's attributes that you'd like to log. By default, it returns an empty array, which tells the package to log *all* the attributes that have changed.
2. `getUnloggableAttributes()` should return an array of all the model's attributes that you'd like to exclude from logging, even if they have changed. By default, the timestamp columns `created_at` and `updated_at` are excluded, as is `deleted_at` if your model also uses Eloquent's `SoftDeletes` trait.

When calculating what attributes to log, the package starts with the "loggable" ones, then removes any "unloggable" ones, so configuring a combination of the two methods should provide the greatest flexibility in choosing what to log. If you want to log the timestamp columns, then explicitly add them to the array returned in `getLoggableAttributes()`.

> Note: any attributes defined as hidden via Eloquent's `hidden` property are obfuscated when they are logged. This should prevent passwords and other sensitive information from being logged in your database in plain text. **Be sure to add the appropriate attributes to this array!**

```
use Cviebrock\EloquentLoggable\Loggable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Loggable;

    // If the password is changed, it will be obfuscated in the logged change
    protected $hidden = [
        'secret_code'
    ];

    // Default value is an empty array, which will log all changed attributes
    public function getLoggableAttributes(): array
    {
        return [];
    }

    // The following attributes won't be logged at all
    public function getUnloggableAttributes(): array
    {
        return [
            'unimportant_field'
        ];
    }
}
```

Usage
-----

[](#usage)

When a model is created, updated, deleted, or restored, a record of that change will be logged. Specifically, a new `Cviebrock\EloquentLoggable\Models\Change` model will be created with the relevant data, including who made the change.

You can get a history of changes for a particular model using the `changes()` relation that the trait sets up:

```
$post = Post::find(1);

$changes = $post->changes;
```

This will be a collection of `Change` models, with the most recent changes first. Each `Change` has the following attributes:

```
// The user who made the change:
$change->user;

// The date of the change:
$change->created_at;

// The attribute changed, the previous and new values of that attribute:
$change->attribute;
$change->old_value;
$change->new_value;
```

You can also work from the other end: finding out what model changed based on a given `Change` model.

```
$change = Change::find(1);

$model = $change->model;
```

### Change Sets

[](#change-sets)

When a change to a model includes several attributes, each attribute that changed creates a new `Change` record/model. However, you can group together all the changes that happened to that model at the same time via the `set` attribute.

(This attribute is really just a hash of the changed model, it's ID, the user that initiated the change, and the time of the change).

```
$change = Change::find(1);

$relatedChanges = Change::inSet($change->set)->get();
```

### Other Query Scopes

[](#other-query-scopes)

You can also search for changes using several other query scopes on the `Change` model:

```
$post = Post::find(1);

$changes = Change::forModel($post)
	->ofType(Change::TYPE_UPDATE)
	->groupedBySet()
	->get();  // or paginate, even!
```

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

[](#configuration)

The package publishes it's configuration file to `config/loggable.php`. The only setting required is `userModel` which should return the fully-qualified class name of your application's user model. The default value -- `App\User::class` -- is usually sufficient.

Bugs, Suggestions and Contributions
-----------------------------------

[](#bugs-suggestions-and-contributions)

Thanks to [everyone](https://github.com/cviebrock/eloquent-loggable/graphs/contributors)who has contributed to this project!

Please use [Github](https://github.com/cviebrock/eloquent-loggable) for reporting bugs, and making comments or suggestions.

See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute changes.

Copyright and License
---------------------

[](#copyright-and-license)

[eloquent-loggable](https://github.com/cviebrock/eloquent-loggable)was written by [Colin Viebrock](http://viebrock.ca) and is released under the [MIT License](LICENSE.md).

Copyright (c) 2017 Colin Viebrock

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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://avatars.githubusercontent.com/u/166810?v=4)[Colin Viebrock](/maintainers/cviebrock)[@cviebrock](https://github.com/cviebrock)

### Embed Badge

![Health badge](/badges/cviebrock-eloquent-loggable/health.svg)

```
[![Health](https://phpackages.com/badges/cviebrock-eloquent-loggable/health.svg)](https://phpackages.com/packages/cviebrock-eloquent-loggable)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B11.0k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1941.5M265](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2328.5M323](/packages/open-telemetry-sdk)[illuminated/console-logger

Logging and Notifications for Laravel Console Commands.

8676.7k](/packages/illuminated-console-logger)

PHPackages © 2026

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