I am developing a quiz application in Laravel and I have some problems with checking the array . I use AngularJS on the front panel, and I use ajax to send objects to the Laravel API. This is an example of a JSON object:
{"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"}]}
The quiz has a name, category and questions. Each question should have a question_text and answers. Each answer has a type, information and is_correct.
Here is the confirmation I wrote:
$this->validate($request, [
'name' => 'required|min:3',
'category' => 'required|min:2',
'questions' => 'required',
'questions.*.question_text' => 'required|min:5',
'questions.*.answers' => 'required'
]);
Name and category checks work fine. The third validation ("questions =>" required ") works fine. Other validations do nothing. For example,
{"name":"SomeName","category":"SomeCategory","questions":[{}]}
passes the check, although the array of questions has an element that has no answers or the question_text field. How does array validation work?