0

I am trying to make a rule if one is empty or not present then other is required but if both are not present then it give error. I have used this but if both are empty then it not give any error

'inventory_storage_container_id'        => 'required_if:inventory_storage_space_id,=,null|integer|exists:inventory_storage_containers,id',
'inventory_storage_space_id'            => 'required_if:inventory_storage_container_id,=,null|integer|exists:inventory_storage_spaces,id',

What i have to do ? This is a different scenario if i not include both field in request body it not give any error but i need an error if both are empty . This topic is not duplicate .

1 Answer 1

2

try required_without

'inventory_storage_container_id'        => 'required_without:inventory_storage_space_id|integer|exists:inventory_storage_containers,id',
'inventory_storage_space_id'            => 'required_without:inventory_storage_container_id|integer|exists:inventory_storage_spaces,id',
Sign up to request clarification or add additional context in comments.

13 Comments

Still it passing the rule if both are not present in the request. I think i need to handle it on controller side not in validation rule .
@MajidJavaid Can I see the controller?
I am asking if no rule for this then i need to handle it on controller side ?
Your case can handle with Laravel validation, you don't need to do it at the controller.
@MajidJavaid this answer is correct. If it's not working for you then you must be doing something incorrectly when sending or checking your input
|

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.