3

How to validate an array object based on another Field. I have an array object details and simple required validation is working fine with:

'details.*.diff_qty' => 'required'

But i want to validate it only if item Id is greater than 0 or not equal to zero with .

'details.*.diff_qty' => 'required_if:details.*.item_id,!=,0'

But not working. Please help. Thanks in Advance.

2 Answers 2

3

Try using required_unless:

'details.*.item_id' => 'required',
'details.*.diff_qty' => 'required_unless:details.*.item_id,0'
Sign up to request clarification or add additional context in comments.

1 Comment

Item id is not required to be greater than 0 . diff_qty is required only if item id is greater than 0
0

use something like

'details.*.diff_qty' =>'required_if:details.*.item_id,gt:details.*.item_id'

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.