2017 © Pedro PelĆ”ez
 

library model-log

A Laravel 5 package to automatically log attributes changes on any of your app models.

image

tpenaranda/model-log

A Laravel 5 package to automatically log attributes changes on any of your app models.

  • Monday, February 5, 2018
  • by tpenaranda
  • Repository
  • 1 Watchers
  • 1 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Laravel ModelLog

Latest Stable Version Total Downloads License, (*1)

A Laravel package to automatically log attributes changes on any of your app models., (*2)

About package

This package is intended for tracking changes of your Eloquent models inside your Laravel application. A new DB table will be created and everytime a model attribute is updated an entry will be automatically created on the DB log table., (*3)

Installation

Install package using Composer., (*4)

$ composer require tpenaranda/model-log

Run migrations to create ModelLog table., (*5)

$ php artisan migrate

[This step is not needed on Laravel >= 5.5] Add service provider and create ModelLog DB table.

Add service provider and alias in config/app.php, (*6)

    'providers' => [
        ...
        TPenaranda\ModelLog\Providers\ModelLogServiceProvider::class,
    ],
    'aliases' => [
        ...
        'ModelLogEntry' => TPenaranda\ModelLog\ModelLogEntry::class,
        'ObservedByModelLog' => TPenaranda\ModelLog\Traits\ObservedByModelLog::class,
    ],

Run ModelLog command in order to create ModelLog DB table., (*7)

$ php artisan model-log:create-log-table

Usage

Add 'ObservedByModelLog' trait to your model and specify attributes you want to observe/track for changes., (*8)

use TPenaranda\ModelLog\Traits\ObservedByModelLog;

class MyModel extends Model
{
    use ObservedByModelLog;

    protected $log = ['my_attribute', 'track_this_column_too'];
}

Now after every update on that model, observed attributes will be logged automatically. Use protected $log = 'all'; (notice the string, not array) to log any change., (*9)

Retrieve log entries:, (*10)

$my_model->logEntries;

Advanced usage

Retrieve log entries using query scopes:, (*11)

\ModelLogEntry::whereModelClass('App\MyModel')->whereAttribute('my_attribute')->whereTo('value_after_change')->get();

Available scopes:, (*12)

  • whereModel(<object>): _Get logs of an specific Eloquent Model_ (example: get log data of MyModel ID #4).
  • whereModelClass(<string/object>): _Get logs for an specific model class_ (example: get entries where MyModel class is involved, regardless of any IDs).
  • whereAttribute(<string>): Get only logs where some specific attribute was changed.
  • whereFrom(<string>): Get only logs with an specific initial value.
  • whereTo(<string>): Get only logs with an specific end value.
  • ModifiedByUser(<numeric/object>): Get changes done by some specific user. Allowed parameters: null, numeric IDs or User object.

The following scopes only accept Carbon objects as parameters: - loggedBefore(<Carbon object>): Retrieve only entries logged prior to specific date. - loggedAfter(<Carbon object>): Retrieve only entries logged after specific date. - withinDateRange(<Carbon object>, <Carbon object>): Retrieve only entries logged after first parameter and prior to second parameter., (*13)

Create (or drop and create) ModelLog table manually:, (*14)

$ php artisan model-log:create-log-table

Flush ModelLog table:, (*15)

\ModelLogEntry::flushAll();

The Versions

05/02 2018

dev-master

9999999-dev

A Laravel 5 package to automatically log attributes changes on any of your app models.

  Sources   Download

GPL-3.0-or-later

The Requires

 

by Tate PeƱaranda

laravel log eloquent model track attributes audit history changes

28/01 2018

1.2.0

1.2.0.0

A Laravel 5 package to automatically log attributes changes on any of your app models.

  Sources   Download

GPL-3.0-or-later

The Requires

 

by Tate PeƱaranda

25/01 2018

1.1.7

1.1.7.0

A Laravel 5 package to automatically log attributes changes on any of your app models.

  Sources   Download

GPL-3.0-or-later

The Requires

 

by Tate PeƱaranda

22/01 2018

1.1.6

1.1.6.0

A Laravel 5 package to automatically log attributes changes on any of your app models.

  Sources   Download

GPL-3.0-or-later

The Requires

 

by Tate PeƱaranda

03/01 2018

0.2.0

0.2.0.0

A Laravel 5 package to automatically log attributes changes on any of your app models.

  Sources   Download

GPL

The Requires

 

by Tate PeƱaranda

03/01 2018

0.1.5

0.1.5.0

A Laravel 5 package to automatically log attributes changes on any of your app models.

  Sources   Download

GPL

The Requires

 

by Tate PeƱaranda

03/01 2018

0.1.4

0.1.4.0

A Laravel 5 package to automatically log attributes changes on any of your app models.

  Sources   Download

GPL

The Requires

 

by Tate PeƱaranda