Laravel验证响应JSON返回额外的数组级别

时间:2015-02-19 19:20:17

标签: php json laravel response

在我的控制器中,我有这个:

$validation = Validator::make(Input::all(), $rules);
if ($validation->fails())
{
    return Response::json($validation->errors());
}

当我预览我的视图时,它不打印任何东西,但在调试器中我看到像这样的json返回,所以就在那里。

{"username":["The username must be at least 6 characters."]}
username: ["The username must be at least 6 characters."]
0: "The username must be at least 6 characters."

我认为它正在制作一个额外的级别并在数组内部放置数组,因此我的javascript在打印内部内容时遇到问题:

0: The username must be at least 6 characters."

如何使这样返回JSON对象,摆脱额外的顶级:

username: ["The username must be at least 6 characters."]
0: "The username must be at least 6 characters."

0 个答案:

没有答案