实现laravel 插入操作日志到数据库的方法

(编辑:jimmy 日期: 2024/10/4 浏览:2)

1 . 创建一个中间件

执行: php artisan make:middleware OperationLog

2 . 在中间件中编写一个writeLog() 或者直接写在handle里面

<"htmlcode">
<"operation_log";

  //定义主键
  protected $primaryKey = "id";
}

4 . 将中间件注册到Kernel.php 文件

/**
 * The application's global HTTP middleware stack.
 *
 * 这些中间件是在对应用程序的每次请求中运行的
 *
 * @var array
 */
protected $middleware = [
    .......,
    .......,
    .......,
    \App\Http\Middleware\OperationLog::class,
  ];

大功告成…

以上这篇实现laravel 插入操作日志到数据库的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。