错误处理程序 Laravel 中的访问请求对象

hct*_*pcu 6 php laravel laravel-5.2

在我的 Laravel 5.2 项目中,我有一个中间件愉快地存储对数据库或文件的请求和响应。在那里,我将序列化/json_encode$request对象用于记录正在发生的一切。(cookies、输入、文件、标题...)

我需要创建一个错误处理程序,它将使用整个请求对象将有关请求的所有内容包含到报告电子邮件中。但ExceptionHandler::report()不接受 Request 作为参数。

Bry*_*yan 5

Laravel 5.2 提供了 helper 方法request(),适用于这个用例:

/**
 * Report or log an exception.
 *
 * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
 *
 * @param  \Exception  $exception
 * @return void
 */
public function report(Exception $exception)
{
    $request = request();

    parent::report($exception);
}
Run Code Online (Sandbox Code Playgroud)