Level 8
Apr 24, 2024
1
Level 1
Tricky Validating
I send an input as an assiciatve array from a form like this:
[
"43813c6a-857e-4ec4-b516-550ffc27183a" => "1"
"f5c9ca97-c07d-48a0-b2c7-0b308a80c543" => "2"
"7883c409-7cf0-4477-a068-e65373830445" => "3"
]
i have a validator like this:
$validated = $request->validate([
'open_ids_texts' => ['required', 'array:'.$possible_option_ids->implode(','), 'size:'.count($possible_option_ids) ,
'open_ids_texts.*' => [$question->required ? 'required' : 'nullable','string'],
],
[
'open_ids_texts.required' => 'The :attribute is required.',
"open_ids_texts.size" => 'Each :attribute must be present.',
'open_ids_texts.*.required' => 'The :attribute is required.',
'input_texts.*.string' => 'The :attribute ha to be a string.',
]
);
i want a costum error text for the keys not beeing in the list. (an equal to the list is also good)
i tried this, but didnt work:
"open_ids_texts.array:".$possible_option_ids->implode(',') =>'Each element in :attribute must be a valid option id',
how to achive that?
Please or to participate in this conversation.