【发布时间】:2019-03-29 11:46:54
【问题描述】:
我验证了一个二维数组,当验证器失败时,validator->errors() 包含:
MessageBag {#1010 ▼
#messages: array:8 [▼
"1.0" => array:1 [▼
0 => "The 1.0 does not match the format d/m/Y."
]
"2.0" => array:1 [▶]
"1.1" => array:1 [▶]
"2.1" => array:1 [▶]
"1.2" => array:1 [▶]
"2.2" => array:1 [▶]
"1.4" => array:1 [▶]
"2.4" => array:1 [▶]
]
#format: ":message"
}
现在我可以像这样访问所有错误:
foreach ($errors->all() as $error) {
}
这会将消息放在$error = "The 1.0 does not match the format d/m/Y.";
如何访问“1.0”键?
【问题讨论】:
-
请问您的意思是如何获取第一条错误消息?
-
不,我想访问每个错误的关键,“1.0”、“1.1”等
-
请检查我的答案
标签: laravel-5.8