lumen-handler.php不反映更新
我修改了Exceptions/Handler.php的render方法,以在出现任何错误时返回自己的响应,而不是呈现lumen的错误页面 这里是我的渲染方法更新lumen-handler.php不反映更新,php,laravel,lumen,Php,Laravel,Lumen,我修改了Exceptions/Handler.php的render方法,以在出现任何错误时返回自己的响应,而不是呈现lumen的错误页面 这里是我的渲染方法更新 /** * Render an exception into an HTTP response. * * @param \Illuminate\Http\Request $request * @param \Exception $e * @return \Illuminate\Http\Response */ pub
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
// return parent::render($request, $e);
return response()
->json([
'errors' => $e
]);
}
我希望它在NotFoundHttpException发生时返回我的响应,但lumen仍然显示其原始错误页面
我知道我应该修改app/Exceptions/Handler.php
,但因为它不能像我预期的那样工作,我改为修改了vendor/laravel/lumen/app/Exceptions/Handler.php
。
这是更新后的文件
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
return response(['test'=> 'test']);
// return parent::render($request, $e);
}
它按照我的预期工作(不显示错误页面,但返回json响应)
在bootstrap/app.php中,似乎正确地设置为调用app\Exceptions\Handler::class
,而不是laravel\lumen\app\Exceptions\Handler::class
/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
我已经尝试重新安装lumen和docker环境。
在安装lumen之后,我尝试修改Handler.php(这在应用程序中没有其他修改),但它不起作用
有人知道我的更改没有反映出来吗?我为
bootstrap/app.php
设置了一个错误的值
我设置如下
require_once uuu DIR_uu./../../vendor/autoload.php'代码>
在我像下面这样修改了这一部分之后,lumen开始能够调用Handler.php方法
require_once uuu DIR_uu.'/../vendor/autoload.php'代码>现在我明白了什么对我的代码有害。在我的bootstrap/app.php中,我编写了require_once uuu DIR_uu.'/../vendor/autoload.php'代码>,但我在这里更改为require_once uuu DIR_uuu./../vendor/autoload.php'代码>,它工作了,我的Handler.php被调用了!