Closed laurenwilliams92 closed 1 year ago
Hmm. Scribe should be able to handle this as is, but try adding a validation for the second level:
'test_questions' => 'array',
+ 'test_questions.*' => 'array',
'test_questions.*.sync_id' => 'nullable|string',
'test_questions.*.score' => 'required|int',
'test_questions.*.answers' => 'array',
'test_questions.*.answers.*.value' => 'nullable|int',
'test_questions.*.answers.*.correct' => 'required|boolean'
Thanks @shalvah that seemed to do the trick.
I'd also like to know how I can write a description and example for the fields within the array from the bodyParameters function in the form request.
I've tried this but no success, and also setting key to include the '*'
'test_questions' => [
'description'=> 'Questions taken in the test',
'example' => [
[
'id' => 832,
'user_test_id' => '42',
'question_id' => '1026',
'question_number' => '1',
'score' => '1',
'correct' => true,
'accessed' => '2023-05-18 15:45:37',
'answered' => '2023-05-18 15:45:40',
'viewed_explanation' => '2023-05-18 15:46:02',
'sync_id' => NULL,
'created' => '2023-05-18 15:45:36',
'modified' => '2023-05-18 15:46:02',
'deleted' => NULL,
'answers' => [
[
'id' => 410,
'user_test_question_id' => '832',
'question_answer_id' => '526',
'question_cloze_group' => NULL,
'value' => NULL,
'correct' => true,
],
],
]
],
'sync_id' => [
'description' => 'Unique sync ID',
'example' => 'b88ae59a-2df1-3369-8c9e-64efb374abac'
]
]
For anyone else having trouble working this out the solution was:
'test_questions.*.answers.*' => 'array',
'test_questions.*.answers.*.value' => 'nullable|int'
'test_questions.*.answers.*.value' => [
'description' => 'Value of answer given, applies to text type questions only',
'example' => 6548748
],
Scribe version
4.19.0
Your question
I can't seem to see any documentation or work out how I can write description and examples for properties inside an array in a form request?
Here's an example of my rules
Screenshot of output![Screenshot 2023-05-28 at 18 50 32](https://github.com/knuckleswtf/scribe/assets/32837730/34590f74-df6c-4422-8e30-ea2a42b842d9)
Docs