2017 © Pedro Peláez
 

library model-logging

image

tait/model-logging

  • Saturday, November 8, 2014
  • by andtait
  • Repository
  • 1 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel Model Logging

About

This package provides some convenient defaults for logging actions that occur on models., (*1)

For example, if you had an admin system where a number of users could mark orders as pending, approved or cancelled, the package would assist in storing what change had been made to the model, and which user made the change., (*2)

This package assumes you're using Eloquent as your ORM., (*3)

Example

Firstly, run the migration to create the "model_logging" table, (*4)

php artisan migrate --package=tait/model-logging

Add the LoggableTrait to a model you want to log actions on, (*5)

<?php

use Tait\ModelLogging\LoggableTrait;

class Order extends Eloquent
{
    use LoggableTrait;

    ...
}

The following example shows how you can add a log that the order has been marked as dispatched., (*6)

$order = Order::find(1);
$order->status = 'dispatched';
$order->save();

$order->saveLog([
    'action' => 'Marked as ' . $order->status
]);

The saveLog method has some sensible defaults for saving the content id, content type, and user id. All settings can be overriden by setting the appropriate key. The following example displays what options you can set on the saveLog method., (*7)

$order->saveLog([
    'user_id' => 34,
    'content_id' => 19,
    'content_type' => 'AnotherModel',
    'action' => 'Made a change to AnotherModel',
    'description' => 'A more detailed optional description of the change made to the model',
]);

The following example displays how you can get all logs, and paginated logs, (*8)

$order = Order::find(1);

// Get all logs
$all_logs = $order->getAllLogs();

// Get paginated logs
$paginated_logs = $order->getPaginatedLogs();

The Versions

08/11 2014

dev-master

9999999-dev

  Sources   Download

The Requires

 

by Andy Tait