0

I am validating two arrays in Laravel frame work. I would like to validate the relation between this two array fields. How can I validate this in request?

'rank.*' => 'integer|min:1|required_with:score.*',
'score.*' => 'numeric|required_with:rank.*',

and also, what should I do if the fields of rank should be unique?

1 Answer 1

1

In this case you need to validate the arrays themselves, and the items in the array separately. Try to write it like this:

[
    'rank' => 'array|required_with:score',
    'score' => 'array|required_with:rank',
    'rank.*' => 'integer|min:1',
    'score.*' => 'numeric',
]
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your response. If the rank fields should be unique.. what shall I do?
You can use 'rank.*' => 'integer|min:1|distinct'
Thank you a lot.. It works :) but when I write required_with in this way: 'score.*' => 'numeric|required_with:rank.*',, It works better..

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.