1

I'm trying to validate three input fields.

If the fields are null then the three fields are not mandatory, but If at least one of them is not empty (null) then all three should be mandatory. But It's doesn't working. If I leave all three fields blank It shows that the three fields are mandatory. It shoud allow the form to be submitted.

public function rules()
    {
      return [
        'a' => 'required_if:b,!=,null|required_if:c,!=,null',
        'b' => 'required_if:a,!=,null|required_if:c,!=,null',
        'c' => 'required_if:a,!=,null|required_if:b,!=,null',
      ];
    }
2

1 Answer 1

0

Dale suggests using required_with instead of required_if, however you can use Preparing Input For Validation it will do the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.