写一个laravel项目,需求是将CURD的记录写入mysql的log表中,
我现在的方案就是CURD结束后自己写的LOG repository 记录一下 ,如下,
$result = $this->customer->add($request->all());
if($result>0){
$this->log->write('新增客户'.$request->input('name'));
}
觉得很不优雅,大家有什么好的思路吗
写一个laravel项目,需求是将CURD的记录写入mysql的log表中,
我现在的方案就是CURD结束后自己写的LOG repository 记录一下 ,如下,
$result = $this->customer->add($request->all());
if($result>0){
$this->log->write('新增客户'.$request->input('name'));
}
觉得很不优雅,大家有什么好的思路吗
1 回答4.1k 阅读✓ 已解决
3 回答1.9k 阅读✓ 已解决
2 回答2.2k 阅读✓ 已解决
1 回答1.4k 阅读✓ 已解决
2 回答2.2k 阅读
1 回答614 阅读✓ 已解决
799 阅读
用laravel 的事件机制记录日志
http://www.golaravel.com/laravel/docs/5.0/events/
注册“新增客户”事件
'App\Events\AddUser'
注册“日志记录”事件监听者
'App\Listeners\LogRecord'
订阅事件
在 EventServiceProvider 中
protected $listen = [
];
触发事件
$result = $this->customer->add($request->all());
event(new AddUser($result ));