2017 © Pedro Peláez
 

library eloquent-logger

Log Eloquent model changes to a designated logs table

image

fish/eloquent-logger

Log Eloquent model changes to a designated logs table

  • Wednesday, November 8, 2017
  • by matfish2
  • Repository
  • 2 Watchers
  • 8 Stars
  • 6,618 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 7 Versions
  • 5 % Grown

The README.md

Eloquent Logger

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

This Laravel 5 package adds logging functionality to Eloquent models. All changes (create, update, delete) will be recorded in a designated logs table. Updates will record only dirty fields., (*2)

Installation

Add to composer.json:, (*3)

"require": {
  "fish/eloquent-logger": "^1.0"
}

Update Composer from the Terminal:, (*4)

composer update

Add the service provider to the the list of providers in your app.php, (*5)

Fish\Logger\LoggerServiceProvider

Publish migration:, (*6)

php artisan logger:init

Run migration:, (*7)

php artisan migrate

Usage

Use the trait on relevant models. E.g:, (*8)

namespace App;

use Illuminate\Database\Eloquent\Model;
use Fish\Logger\Logger;

class Post extends Model
{
  use Logger;
}

Retrieving logs for a model:, (*9)

Post::find(1)->logs

Retrieving model from log (if the action was not deleted):, (*10)

Fish\Logger\Log::find(1)->loggable;

Retrieve the state of the model at a certain point of time:, (*11)

Post::find(1)->logs()->stateOn('2015-02-02 13:00:00');

To retrieve the state of a deleted model:, (*12)

Fish\Logger\Log::entity(Post::class, 1)->stateOn('2016-01-01 12:00:00');

The model will be retrieved even if the passed timestamp occured after it was already deleted., (*13)

The Log contains the following properties:, (*14)

  • user_id integer: User who did the action. if there is no authenticated user, set to null
  • action string: type of action - created, updated or deleted
  • before array: state of the model before the action. If the action is created set to null
  • after array: state of the model after the action. If the action is deleted set to null
  • created_at datetime: action's timestamp

Query helpers

  • wasCreated, wasUpdated or wasDeleted - filter by action.
  • between - filter by date range.

Example:, (*15)

Post::find(1)->logs()
            ->wasUpdated()
            ->between('2015-01-01','2015-02-01')
            ->get();

The Versions

08/11 2017

dev-master

9999999-dev

Log Eloquent model changes to a designated logs table

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matanya Fishaimer

laravel log eloquent events model

04/04 2016

1.3.2

1.3.2.0

Log Eloquent model changes to a designated logs table

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matanya Fishaimer

laravel log eloquent events model

23/02 2016

1.3.1

1.3.1.0

Log Eloquent model changes to a designated logs table

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matanya Fishaimer

laravel log eloquent events model

19/02 2016

1.3

1.3.0.0

Log Eloquent model changes to a designated logs table

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matanya Fishaimer

laravel log eloquent events model

04/02 2016

1.2

1.2.0.0

Log Eloquent model changes to a designated logs table

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matanya Fishaimer

laravel log eloquent events model

01/02 2016

1.1

1.1.0.0

Log Eloquent model changes to a designated logs table

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matanya Fishaimer

laravel log eloquent events model

30/01 2016

1.0

1.0.0.0

Log Eloquent model changes to a designated logs table

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matanya Fishaimer

laravel log eloquent events model