John Davidson

php - required_if not case in Laravel

0 comments
Message:


I have this validation:


 'target' => ['required', Rule::in(['ads', 'users',...])],
'expires_at' => 'required_if:target,!=,ads',

I need to make expires_at is not required if the target is ads if the user chooses other options make expires_at required again!



My Answer:
'required_if:source,website'

This validation rule states that the 'target' field is required if the 'source' field is equal to 'website'. If the 'source' field is not equal to 'website', then the 'target' field is not required.

Rate this post

4 of 5 based on 5961 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us