Laravel 5.2中的数组验证

迪米塔尔·斯帕索夫斯基(Dimitar Spasovski)

我正在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字段,但仍通过验证。数组验证如何工作?

爱国者

这是一个已知的问题。

有一个开放的拉取请求,用于解决“必需”的验证。您可以在此处遵循此请求

还有第二个请求请求,通过“ required_ *”验证(required_with等)解决了该问题。您可以在此处遵循该请求

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章