I have just solved a somewhat similar problem with validation. I think when we need to apply a COMPLEX validation rule that involves MULTIPLE attributes in the same request, an after hook can be implemented:
class YourRequest extends FormRequest
{
public function withValidator($validator)
{
$validator->after(function ($validator) {
foreach ($this->input('line_items') as $index => $lineItem) {
if ($lineItem->userProduct->is_template_product && ! Arr::get($lineItem, 'image_name')) {
$validator->errors()->add("line_items.{$index}.image_name", 'Image name is required.');
}
}
});
}
public function rules()
{
return [
// ...
];
}
}