Required_if with more than one field in Laravel 5.3

3

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 required_if , but I believe that 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',

In the way the signature-one field is, it will be mandatory even though one of the other two is null , and I wanted it to be mandatory only if both were null . Can anyone help me?

    
asked by anonymous 05.02.2017 / 19:17

1 answer

3

The test for this type is required_without_all , where translation says:

  

The field in validation 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',

References

06.02.2017 / 00:00