This article brings you relevant knowledge aboutlaravel, which mainly introduces related issues about using middleware to record user request logs, including creating middleware, registering middleware, and recording User access and other contents, let’s take a look at them below. I hope it will be helpful to everyone.
[Related recommendations:laravel video tutorial]
php artisan make:middleware 中间件名称(TraceRecordMiddleware)
$app->middleware([ App\Http\Middleware\TraceRecordMiddleware::class ]);
Copy after login
$request->getMethod(), 'secure' => $request->getScheme(), 'uri' => $request->getRequestUri(), 'port' => $request->getPort() ]); return $next($request); } }
json_encode($request->all(), JSON_UNESCAPED_UNICODE), 'response' => $response->getContent() ?: '', 'status' => $response->getStatusCode() ]); return $response; } }
$session->get('user_info.id', '未知'), 'username' => $session->get('user_info.username', '未知'), 'method' => $request->getMethod(), 'secure' => $request->getScheme(), 'uri' => $request->getRequestUri(), 'response' => $response->getContent() ?: '', 'status' => $response->getStatusCode() ]); return $response; } }
[Related recommendations:laravel video tutorial]
The above is the detailed content of Detailed example of laravel using middleware to record user request logs. For more information, please follow other related articles on the PHP Chinese website!