Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
lumen-handler.php不反映更新_Php_Laravel_Lumen - Fatal编程技术网

lumen-handler.php不反映更新

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

我修改了Exceptions/Handler.php的render方法,以在出现任何错误时返回自己的响应,而不是呈现lumen的错误页面

这里是我的渲染方法更新

/**
 * 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被调用了!