我正在Laravel中开发测验应用程序,并且数组验证存在一些问题。我在前端使用AngularJS,并使用ajax将对象发送到Laravel API。这是一个示例JSON对象:
{"name":"TestName","category":"TestCategory","questions":[{"answers":[{"type":"radio","information":"Test answer two","is_correct":false,"$$hashKey":"object:28"},{"type":"radio","information":"Test answer One","is_correct":false,"$$hashKey":"object:22"}],"$$hashKey":"object:13","question_text":"Test Question One"}]}
测验有名称,类别和问题。每个问题必须具有question_text和答案。每个答案都有类型,信息和is_correct。
这是我写的验证:
$this->validate($request, [
'name' => 'required|min:3',
'category' => 'required|min:2',
'questions' => 'required',
'questions.*.question_text' => 'required|min:5',
'questions.*.answers' => 'required'
]);
名称和类别验证可以正常工作。第三个验证('questions =>'required')也可以正常工作。其余的验证无效。例如,
{"name":"SomeName","category":"SomeCategory","questions":[{}]}
尽管问题数组的元素没有答案或question_text字段,但仍通过验证。数组验证如何工作?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句