Required_if with more than one field in Laravel 5.3

Asked

Viewed 324 times

3

I have the following situation: I want one 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 I’d use the required_if, however I believe that can only declare one field and several values, but no more than one field.

The code is 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 manner that is the Signature-one field will be mandatory even if one of the other two is null, and I wanted it to be mandatory only if the two were null. Can someone help me?

  • 1

    and then the solution was what I needed?

  • 1

    It was yes expensive, very obg. I looked at the documentation, but I am not good in English and I let this kind of validation pass. vlw

1 answer

2


The test for this guy is with required_without_all, where translation says:

The field under 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:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.