dev-master
9999999-dev https://github.com/thephpthemightysapien/loggable:This packages allows the laravel models to have automatic logging
MIT
The Requires
The Development Requires
laravel loggable logs themightysapien
Wallogit.com
2017 © Pedro Peláez
:This packages allows the laravel models to have automatic logging
Loggable is a Laravel 5 package which helps users to keep simple log of their model CRUD operations. ., (*1)
Via Composer, (*2)
``` bash $ composer require themightysapien/loggable, (*3)
Add the service provider to the providers array in app.php ``` bash Themighty\Loggable\LoggableServiceProvider //THen do vendor:publish from the artisan command to copy the migration file migrate it php artisan vendor:publish php artisan migrate
``` php //use LoggableModelTrait in any of your models whose CRUD logs you want to keep class DemoModel extends \Eloquent { use Themighty\Loggable\Traits\LoggableModelTrait }, (*4)
Then you need to define a **getLogData()** function as
``` php
public function getLogData()
{
return array(
'routeName' => 'admin.inventories',
'title' => 'name',
'modelName' => 'Inventory Item',
'user' => \Auth::id()
);
}
routeName : leave it empty if you dont want the log data to be a link, or you can keep name of the resource route., (*5)
title : this is the DB table column whose data will be shown in the log., (*6)
modelname : Readable model name for the log., (*7)
user : the id of the user who performed the actions in the model., (*8)
THen you can display the logs as follows, (*9)
``` php //for all logs loop through \Themightysapien\Loggable\Logs::all() or filter it however you like, (*10)
//for model specific logs you can call $model->logs to get model specific logs, (*11)
//then inside the loop you can access the user with ->user property, (*12)
foreach($model->logs as $log){
echo $log->getModelName().' || '.$log->getLogEntry().' ||'.$log->getAction();
echo '
';
echo 'By :'.$log->user->name.' at '.$log->created_at;
}
```
The above code will produce the result like, (*13)
Inventory Item || Milk || added, (*14)
By themightysapien at 2015-12-12 00:00:00, (*15)
Please see CONTRIBUTING for details., (*16)
If you discover any security related issues, please email themightysapien@gmail.com instead of using the issue tracker., (*17)
The MIT License (MIT). Please see License File for more information., (*18)
:This packages allows the laravel models to have automatic logging
MIT
laravel loggable logs themightysapien