John Davidson

php - required_if not case in Laravel


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:

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 3772 votes


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