[英]Laravel: Passing request to core function?
In order to report my error I need access to a Request
, but I can't get one in my report function in /app/Exceptions/Handler.php
? 为了报告我的错误,我需要访问一个
Request
,但是在/app/Exceptions/Handler.php
报告函数中/app/Exceptions/Handler.php
?
Reporting: 报告:
public function report(Exception $exception) {
if (strlen($exception->getMessage()) > 0 && $this->shouldReport($exception)) {
$agent = new Agent();
$errorLog = new ErrorLog;
$errorLog->error_message = $exception->getMessage();
$errorLog->error_file = $exception->getFile();
$errorLog->error_line = $exception->getLine();
$errorLog->request_ip = $request->ip();
$errorLog->request_url = $request->root();
$errorLog->request_device = $agent->isDesktop() ? 'Desktop' : ($agent->isMobile() ? 'Mobile' : 'Tablet');
$errorLog->request_system = $agent->platform() . ' ' . $agent->version($agent->platform());
$errorLog->request_browser = $agent->browser();
$errorLog->error_happened_to = (Auth::check() ? Auth::user()->username : 'Guest');
$errorLog->save();
}
parent::report($exception);
}
Failing to pass one results in the following error: 不通过将导致以下错误:
Undefined variable: request
未定义的变量:请求
您可以在任何地方直接使用辅助函数request()
访问请求,在这种情况下,只需使用request()->ip()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.