rummykhan / moloquent-logger
Log Moloquent model changes to logs table
1.0.1
2017-03-17 15:14 UTC
Requires
- jenssegers/mongodb: ^3.1
- laravel/framework: 5.*
This package is not auto-updated.
Last update: 2024-12-22 03:33:54 UTC
README
A Laravel 5 package to log changes of your Mongodb Models.
Dependencies
jenssegers/mongodb
Installation
Install using composer:
composer require rummykhan/moloquent-logger
Add Service Provider
Add service provider in config/app.php
:
RummyKhan\MoloquentLogger\MoloquentLoggerServiceProvider::class,,
Publish Configuration
Publish the configuration using command:
php artisan vendor:publish
Configure your application logging behavior
In config/moloquent-logger.php
there are certain options which you can use to control the logging behavior of you application.
Add MoloquentLogger Trait
Any Model for which you want to track changes add MoloquentLogger
Trait to that Model.
e.g.
<?php namespace App; use Jenssegers\Mongodb\Eloquent\Model; use RummyKhan\MoloquentLogger\Logger\MoloquentLogger; class Post extends Model{ use MoloquentLogger; }
Log Collection Document Structure
{
"_id" : ObjectId("58bf371ddd73170408004836"),
"request" : [],
"before" : {
"name" : "eod nhoj",
"type" : "admin"
},
"after" : {
"name" : "john doe",
"type" : "user"
},
"before_model" : {
"_id" : "58bf3388dd7317040800482e",
"name" : "eod nhoj",
"email" : "john@doe.ae",
"updated_at" : "2017-03-07 22:41:20",
"created_at" : "2017-03-07 22:26:16",
"type" : "admin"
},
"after_model" : {
"_id" : "58bf3388dd7317040800482e",
"name" : "john doe",
"email" : "john@doe.ae",
"updated_at" : "2017-03-07 22:41:20",
"created_at" : "2017-03-07 22:26:16",
"type" : "user"
},
"scope" : {
"file" : "/home/user/laravel/routes/web.php",
"line" : 29,
"function" : "save",
"class" : "Illuminate\\Database\\Eloquent\\Model",
"object" : {},
"type" : "->",
"args" : []
},
"user_id" : null,
"action" : "update",
"moloquent_type" : "App\\User",
"moloquent_id" : "58bf3388dd7317040800482e",
"updated_at" : ISODate("2017-03-07T22:41:33.359Z"),
"created_at" : ISODate("2017-03-07T22:41:33.359Z")
}
Document Description
Access Logs
To access logs for a record
$post = Post::find(1); dd($post->logs);
Get State After
Get state after specific date, using string date format understandable by PHP Date
.
$post = Post::find(1); dd($post->stateAfter('2017-03-17'));
Get State Before
Get state before specific date, using string date format understandable by PHP Date
.
$post = Post::find(1); dd($post->stateBefore('2017-03-17'));