You would have to use recursion. But I would not do that. Do not validate what you do not own cause it can break down pretty quickly. Instead use Value/DataTransfer objects and just use them to fetch the data.
Validating Remote API Data
Hey All.
I'm building a service that fetches an array from a user's remote account through a RESTful API.
The data comes in as a large nested array, and I'd like to use a Validator instance with rules and messages to show errors to the user, basically items that we require, that may not have been sent.
I have the basics started, but I'm wondering how to loop through nested items and create appropriate messages to pass back to Vuex.
The data is structured similar to this:
[
'item' => [
"name" => "Item name",
"notes" => "Here are some notes.",
"nested_1" => [
0 => [
"name" => "Item name",
"notes" => "Here are some notes.",
"nested_2" => [
0 => [
"name" => "Nested item name",
"notes" => "Here are notes.",
"nested_3" => [
0 => [
"name" => "Nested item",
"notes" => "Here are notes."
]
]
]
]
],
1 => [
"name" => "Nested item name",
"notes" => "No notes other than this.",
"nested_2" => [
0 => [
"name" => "Nested item name",
"notes" => "Here are notes.",
"nested_3" => [
0 => [
"name" => "Nested item",
"notes" => "Here are notes."
]
]
]
]
]
]
]
]
There can be any number of arrays that are nested up to 3 levels deep, so is there an article or technique anyone can point me to that will explain how to validate all these items while still being able to keep all the errors coupled to their given item?
Yes I've Googled. I can't find anything except how to validate forms in your own Laravel API. And of course I also have the documentation open as I go so please don't point me there.
Thanks
Please or to participate in this conversation.