Home > Backend Development > PHP Tutorial > Laravel Log模块设计

Laravel Log模块设计

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:13:53
Original
974 people have browsed it

写一个laravel项目,需求是将CURD的记录写入mysql的log表中,
我现在的方案就是CURD结束后自己写的LOG repository 记录一下 ,如下,

<code>$result = $this->customer->add($request->all());
if($result>0){
    $this->log->write('新增客户'.$request->input('name'));
}</code>
Copy after login
Copy after login

觉得很不优雅,大家有什么好的思路吗

回复内容:

写一个laravel项目,需求是将CURD的记录写入mysql的log表中,
我现在的方案就是CURD结束后自己写的LOG repository 记录一下 ,如下,

<code>$result = $this->customer->add($request->all());
if($result>0){
    $this->log->write('新增客户'.$request->input('name'));
}</code>
Copy after login
Copy after login

觉得很不优雅,大家有什么好的思路吗

用laravel 的事件机制记录日志
http://www.golaravel.com/laravel/docs/5.0/events/

注册“新增客户”事件

'App\Events\AddUser'

注册“日志记录”事件监听者

'App\Listeners\LogRecord'

订阅事件

在 EventServiceProvider 中

protected $listen = [

<code>'App\Events\AddUser' => [
    'App\Listeners\LogRecord',
],</code>
Copy after login

];

触发事件

$result = $this->customer->add($request->all());
event(new AddUser($result ));

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template