There is a better way to do this now. I'm not sure the exact minimum version of Laravel that supports this but I'm running 5.5 and this approach works.
Assuming you have request data like:
index:0
is_required:1
type:select
name:favorite color
title:What is your favorite color?
meta[0][key]:subtitle
meta[0][value]:If you have multiple favorites, pick your favorite-favorite.
meta[1][key]:default_value
meta[1][value]:Pink
options[0][index]:0
options[0][value]:Red
options[1][index]:3
options[1][value]:Pink
options[2][index]:1
options[2][value]:Blue
options[3][index]:2
options[3][value]:Green
Your validation rules can look like:
return [
'index' => 'required|integer|min:0',
'is_required' => 'required|boolean',
'type' => [
'required',
Rule::in($this->types_enum)
],
'name' => 'required|string|max:64',
'meta' => 'sometimes|array',
'meta.*.key' => 'required|string|max:64',
'meta.*.value' => 'required|string',
'options' => 'sometimes|array',
'options.*.index' => 'required|integer|min:0',
'options.*.value' => 'required|string',
];
Note the trick is just to use the wildcard operator (*) with dot notation to represent the index value of the array item itself.