2017 © Pedro Peláez
 

library eloquent-loggable

Make your eloquent Model loggable

image

devitek/eloquent-loggable

Make your eloquent Model loggable

  • Saturday, August 20, 2016
  • by CaporalDead
  • Repository
  • 3 Watchers
  • 4 Stars
  • 31 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

Make your eloquent Model loggable

SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

This package provide a simple way to make your Eloquent's model loggable. It works like the Gedmo/Loggable extension for doctrine., (*2)

Installation

Run :, (*3)

composer require devitek/eloquent-loggable

Into your config/app.php add the service provider :, (*4)

'providers' => [
    // Other Service Providers

    Devitek\Laravel\Eloquent\Loggable\EloquentLoggableServiceProvider::class,
],

Get the migration :, (*5)

php artisan vendor:publish --provider="Devitek\Laravel\Eloquent\Loggable\EloquentLoggableServiceProvider" --tag="migrations"

and then run :, (*6)

php artisan migrate

How to use it

In your Eloquent model add :, (*7)

<?php

use \Devitek\Laravel\Eloquent\Loggable;

class MyModel extends Model
{
    use Loggable;

    protected $versioned = [
        'name',
        'other_field',
        'another_field',
        'again_another_field',
    ];

    protected $reason = 'my_reason_field';
}

Now, each time you'll persist your model, all fields that are declared in the versioned property will be checked (if dirty) and then logged., (*8)

The reason property indicates which field will be used to have a log message. It's not required, by default the log message will be empty. This field will be unset before persist so you can use a dynamic field., (*9)

Get log entries

You now have a method on your model : logEntries which is a morphTo relationship., (*10)

$logEntries = $model->logEntries();

foreach ($logEntries as $logEntry) {
    /**
     * LogEntry object :
     * action, logged_at, object_id, version, reason, data (as json), user_id
     */
}

Revert

You can revert your model to a previous state using the revert method like so :, (*11)

$model = MyModel::find($id);

$model->revert(); // Revert to the first revision
$model->revert(5); // Revert to the 5th revision

Enjoy it ! Feel free to fork :) !, (*12)

The Versions

20/08 2016

dev-master

9999999-dev

Make your eloquent Model loggable

  Sources   Download

MIT

The Requires

 

by Thomas SIEFFERT

laravel eloquent loggable

20/08 2016

0.1.1

0.1.1.0

Make your eloquent Model loggable

  Sources   Download

MIT

The Requires

 

by Thomas SIEFFERT

laravel eloquent loggable

16/09 2015

0.1

0.1.0.0

Make your eloquent Model loggable

  Sources   Download

MIT

The Requires

 

by Thomas SIEFFERT

laravel eloquent loggable