如何在Laravel中显示像JSON一样的路由错误?

时间:2016-09-10 15:12:25

标签: laravel laravel-5.2 laravel-5.3

当我在URL中调用underined route时,我将Laravel错误视为HTML页面:

GROUP BY

如何在JSON格式响应中替换它?

1 个答案:

答案 0 :(得分:2)

您可以在app\Exceptions\Handler.php@render()方法中创建JSON响应:

if ($e instanceof MethodNotAllowedHttpException) {
    return response()->json($data);
}

https://laravel.com/docs/5.3/errors#render-method