【发布时间】:2016-05-24 13:29:33
【问题描述】:
我正在使用 Laravel 5.1 构建一个 RESTful API - 发出发布请求时,我会验证输入,如果输入无效,我会抛出异常。
当前响应样本:
{
"message": "{\"email\":[\"The email field is required.\"]}",
"status_code": 400
}
如何让我的回复看起来像这样:
{
"message": {
"email": "The email field is required."
},
"status_code": 400
}
这是我抛出异常的方式:
$validator = Validator::make($this->request->all(), $this->rules());
if ($validator->fails()) {
throw new ValidationFailedException($validator->errors());
}
【问题讨论】:
标签: php json rest exception laravel-5