Programming :  Student Freelance Forum For Work Experience Builders' (CertificationPoint) The fastest message board... ever.
 
How to access nested item in Rule::requiredIf() validation
Posted by: adcertpoint (Moderator)
Date: July 22, 2021 07:21PM

I'm trying to validate an array inside a custom Request. The rule evaluates to required if two conditions are met:

attribute3 is true
another column from the same array is true

Here's what I'm doing:

public function rules()
{
return [
'attribute1' => 'required',
'attribute2' => 'required',
'attribute3' => 'required',
...
'attribute10.*.column3' => Rule::requiredIf(fn() => $this->attribute3), // <- array
'attribute10.*.column4' => Rule::requiredIf(fn() => $this->attribute3), // <- array
'attribute10.*.column5' => Rule::requiredIf(fn() => $this->attribute3), // <- array
];
}

What I really need is this:

'attribute10.*.column4' => Rule::requiredIf(fn($item <- magically hint this currently looped item) => $this->attribute3 && $item->column2 <- so I can use it like this), // <- array

Options: ReplyQuote


Sorry, only registered users may post in this forum.
This forum powered by Phorum.