laravel中默认异常的处理是由app/Exceptions/Handler.php处理的,其中rendor方法,就是用来返回http响应的,我们修改这个方法
public function render($request, Exception $e)
{
if($e && !env("APP_DEBUG")){
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
$code = FlattenException::create($e)->getStatusCode();
if(!in_array($code,[404,503])){
return response()->view("errors.".'wrong',[],500);
}
return response()->view("errors.".$code,[],$code);
}
return parent::render($request, $e);
}