themightysapien/loggable
Composer 安装命令:
composer require themightysapien/loggable
包简介
:This packages allows the laravel models to have automatic logging
README 文档
README
Loggable is a Laravel 5 package which helps users to keep simple log of their model CRUD operations. .
Install
Via Composer
$ composer require themightysapien/loggable
Add the service provider to the providers array in app.php
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
Usage
//use LoggableModelTrait in any of your models whose CRUD logs you want to keep class DemoModel extends \Eloquent { use Themighty\Loggable\Traits\LoggableModelTrait }
Then you need to define a getLogData() function as
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.
title : this is the DB table column whose data will be shown in the log.
modelname : Readable model name for the log.
user : the id of the user who performed the actions in the model.
THen you can display the logs as follows
//for all logs loop through \Themightysapien\Loggable\Logs::all() or filter it however you like //for model specific logs you can call $model->logs to get model specific logs //then inside the loop you can access the user with ->user property foreach($model->logs as $log){ echo $log->getModelName().' || '.$log->getLogEntry().' ||'.$log->getAction(); echo '<br>'; echo 'By :'.$log->user->name.' at '.$log->created_at; }
The above code will produce the result like
Inventory Item || Milk || added
By themightysapien at 2015-12-12 00:00:00
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email themightysapien@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-18