以下是handler.php文件中的函数:
public function render($request, Exception $exception)
{
if ($exception instanceof CustomException) {
return response()->view('errors.500', [], 500);
}
return parent::render($request, $exception);
}
我在以下路径中有一个名为500.blade.php的刀片服务器:
C:\xampp\htdocs\sharp\resources\views\errors
以下是我要处理的错误500(无任何处理):
localhost is currently unable to handle this request.
HTTP ERROR 500
如果添加上述public function render($request, Exception $exception)
函数,则if条件将不起作用,并显示默认错误:
Whoops, looks like something went wrong.
我不确定为什么if条件没有收到错误。
错误500:
答案 0 :(得分:2)
如果您希望所有status code = 500
都经过特定页面,则可以执行以下操作:
if ($this->isHttpException($exception)) {
if ($exception->getStatusCode() == 500) {
return response()->view('errors.500' , [], 500);
}
}
if ($exception instanceof ErrorException) {
abort(500);
}
return parent::render($request, $exception);
但是如果错误仅是instanceof CustomException
,您的方法就可以正常工作。