先上图:

laravel安装Whoops样式错误处理器教程

 

安装步骤:

1、打开你的laravel项目目录

2、Shift+右键在这里打开命令行

3、输入命令:

composer require filp/whoops:~1.0.

4、修改 app/Exceptions/Handler.php 

render()方法中添加一个Whoops样式的处理情况,就像下面这样:

 1     /**
 2      * Render an exception into an HTTP response.
 3      *
 4      * @param  \Illuminate\Http\Request  $request
 5      * @param  \Exception                $exception
 6      * @return \Illuminate\Http\Response
 7      */
 8     public function render($request, Exception $exception)
 9     {
10         if ($this->isHttpException($exception)) {
11             return $this->renderHttpException($exception);
12         }
13 
14         if (config('app.debug')) {
15             return $this->renderExceptionWithWhoops($exception);
16         }
17 
18         return parent::render($request, $exception);
19     }
20 
21     /**
22      * Render an exception using Whoops.
23      *
24      * @param  \Exception                $exception
25      * @return \Illuminate\Http\Response
26      */
27     protected function renderExceptionWithWhoops(Exception $exception)
28     {
29         $json = new \Whoops\Handler\JsonResponseHandler;
30         $json->onlyForAjaxRequests(true);
31 
32         $whoops = new \Whoops\Run;
33         $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
34         $whoops->pushHandler($json);
35 
36         return new \Illuminate\Http\Response(
37             $whoops->handleException($exception),
38             $exception->getStatusCode(),
39             $exception->getHeaders()
40         );
41     }

然后自己写一个错误测试一下!

如图:

laravel安装Whoops样式错误处理器教程

 

相关文章:

  • 2021-10-27
  • 2021-10-06
  • 2022-12-23
  • 2021-04-01
  • 2021-05-31
  • 2022-01-30
  • 2022-12-23
  • 2021-08-14
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2021-11-21
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案