Complete the code to require the 'email' field only if 'subscribe' is true.
$request->validate([
'email' => '[1]:subscribe,true'
]);The required_if rule makes the field required only when another field has a given value.
Complete the code to require 'password' only when 'change_password' is present in the request.
$request->validate([
'password' => '[1]'
]);The required_with rule requires the field only if another specified field is present.
Fix the error in the validation rule to require 'phone' only if 'contact_method' equals 'phone'.
$request->validate([
'phone' => 'required_if:[1]'
]);The required_if rule syntax is required_if:otherfield,value. Commas separate the field and value.
Fill both blanks to require 'address' only when 'country' is 'US' and 'state' is present.
$request->validate([
'address' => '[1]:country,US|[2]:state'
]);required_if checks the value of 'country'. required_with requires 'address' if 'state' is present.
Fill all three blanks to require 'discount_code' only if 'user_type' is 'member', 'purchase_amount' is greater than 100, and 'promo' is present.
$request->validate([
'discount_code' => '[1]:user_type,member|[2]:purchase_amount,100|[3]:promo'
]);required_if checks 'user_type'. gt checks if 'purchase_amount' is greater than 100. required_with requires the field if 'promo' is present.