Size Validation Rule on Array Based on Other Field

Posted 3 months ago by xtremer360

I'm running into a situation where I have two fields where one needs to be completely validated before it can proceed to the second field. The reasoning is due to using the value of field1 to retrieve a property off of a Model that would be used for field2's validation. I'm doing the following validation in a form request class.

My question is what can I do so that I can take care of the size rule after regular validation of the two fields are successful?

$sizeNeeded = Model::where($this->input('field1_id')->first()->number_of_sides;

'field1' => ['required', 'integer', 'exists: tablename, id'],
'field2' => ['required', 'array', 'size:'.$sizeNeeded],

Please sign in or create an account to participate in this conversation.