I want to set require validation for array of objects in laravel and used following rule:
[
'translations.*.languageId' => ['required', 'numeric', Rule::in(Language::all()->pluck('id'))],
'translations.*.data.title' => 'required|string',
]
but there is problem when i send request without translations key the validate function does not throw require error for translation key.
so i add translations key separately too.
[
'translations' => ['required', 'array'],
'translations.*.languageId' => ['required', 'numeric', Rule::in(Language::all()->pluck('id'))],
'translations.*.data.title' => 'required|string',
]
But there is a problem if an extra key is sent that should not be in the translations array (like locale), it can still be seen in the output of the validate function.
how can i prevent this unexpected result?