我正在使用L5表单请求,我非常喜欢Taylor!现在,我正在进行一些AJAX请求,但仍然希望保留我的表单请求。问题是,在验证错误的情况下,验证器只返回422错误响应并闪烁错误,但我的AJAX前端期望从服务器接收一个非常特定的响应格式,无论验证是否成功。
我希望将验证错误的响应格式化为以下内容:
return json_encode(['Result'=>'ERROR','Message'=>'//i get the errors..no problem//']);
My problem is how to format the response for the form requests, especially when this is not global but done on specific form requests.
I have googled and yet not seen very helpful info. Tried this method too after digging into the Validator
class.
// added this function to my Form Request (after rules())
public function failedValidation(Validator $validator)
{
return ['Result'=>'Error'];
}
Still no success.