Question:
I have the following situation: I want a field to be mandatory only if the other two are null
, if one of the other two is not null
this field is no longer mandatory.
I thought about using the required_if
, however I believe it can only declare one field and several values, but not more than one field.
The code looks like this:
'signature-one'=>'required_if:signature-two,null|required_if:signature-three,null|integer',
'signature-two'=>'nullable|sometimes|integer',
'signature-three'=>'nullable|sometimes|integer',
the way it is, the signature-one field is going to be mandatory even if one of the other two is null
, and I wanted it to be mandatory only if both were null
. Can someone help me?
Answer:
The test for this type is with required_without_all , where translation says:
The field being validated must be present and not empty only when all other specified fields are not present.
Validation:
'signature-one'=>'required_without_all:signature-two,signature-three',
'signature-two'=>'nullable|sometimes|integer',
'signature-three'=>'nullable|sometimes|integer',
Referencias: