【发布时间】:2018-11-09 12:20:39
【问题描述】:
我有一个 Json 数据对象,如下所示
{
"name": "something",
"location": {
"city": "some where",
"country": "some where",
}
}
用于验证请求的规则是
[
'name' => 'required',
'location.city' => 'required',
'location.country' => 'required'
]
返回类似
的错误信息{
"name": [
"The name field is required."
],
"location.city": [
"The location.city field is required."
],
"location.county": [
"The location.country field is required."
]
}
如何将错误消息格式化为像请求一样的嵌套数组。
{
"name": [
"The name field is required."
],
"location": {
"city": [
"The city field is required"
],
"country": [
"The country field is required"
]
}
}
任何可用的默认方法?
我正在使用Illuminate\Foundation\Http\FormRequest
【问题讨论】:
标签: laravel validation laravel-5.7