@sti3bas and @tykus both these solutions look like great options.
I am quite new to Laravel, so could you just tell me where the code is dropped in.
@tykus I presume the closure goes like this, if so I still get the old message.
$validatedData = request()->validate([
//...
'line.*.description' => 'required',
'line.*.retail_price' => function ($attribute, $value, $fail) {
[$group, $position, $name] = explode('.', $attribute);
$fieldName = Str::replace('_', $name);
// required rule
if (!$this->validateRequired($attribute, $value)) {
$fail('The ' . $fieldName . ' on line ' . $position + 1 . ' is required.');
}
// min rule
$minValue = 0;
if (!$this->validateMin($attribute, $value, [$minValue])) {
$fail('The ' . $fieldName . 'on line ' . $position + 1 . ' must be at least ' . $minValue);
}
},
// ...
]);
I read https://laravel.com/docs/6.0/validation#using-closures but not sure that docs method works when using $validatedData = request()->validate([//**]);