创建中间件
Middleware/OperationLogs.php
public function handle($request, Closure $next){ $route = $request->decodedPath(); $user = $request->user(); $method = $request->method(); if ("GET" != $method) { $model = new OperationLog(); $model->uid = $user->id; $model->route = $route; $model->save(); } return $next($request);}复制代码
注册中间件
Kernel.php
protected $routeMiddleware = [ ... 'operation' => \App\Http\Middleware\OperationLogs::class, ];复制代码