Recall & Review
beginner
What is conditional validation in Laravel?
Conditional validation in Laravel means applying validation rules only when certain conditions are met. It helps to validate data dynamically based on other input values.
Click to reveal answer
beginner
How do you apply a validation rule only if another field has a specific value?
You can use the
required_if rule. For example, 'field2' => 'required_if:field1,value' means field2 is required only if field1 equals value.Click to reveal answer
intermediate
What Laravel method allows you to add validation rules conditionally in a fluent way?
The
sometimes method lets you add rules only when a condition is true. For example, $validator->sometimes('field', 'rule', fn() => condition).Click to reveal answer
intermediate
Explain the difference between
required_if and sometimes in Laravel validation.required_if is a rule that makes a field required based on another field's value. sometimes is a method to apply rules only when a condition is true, giving more control over when validation runs.Click to reveal answer
beginner
How can you validate a field only if another field is present in the request?
Use the
required_with rule. For example, 'field2' => 'required_with:field1' means field2 is required only if field1 is present in the input.Click to reveal answer
Which Laravel validation rule makes a field required only if another field equals a specific value?
✗ Incorrect
required_if makes a field required only when another field has a given value.What does the
sometimes method do in Laravel validation?✗ Incorrect
sometimes applies validation rules only if a given condition is true.Which rule requires a field only if another field is present in the input?
✗ Incorrect
required_with requires a field only if another specified field is present.How do you add conditional validation rules using a closure in Laravel?
✗ Incorrect
The
sometimes method accepts a closure to conditionally apply rules.What happens if you use
required_if:status,active on a field?✗ Incorrect
The field becomes required only when the
status field equals 'active'.Describe how you would validate a form field only when another field has a specific value in Laravel.
Think about rules that depend on other fields' values.
You got /3 concepts.
Explain the difference between the
sometimes method and the required_if rule in Laravel validation.One is a method for adding rules conditionally, the other is a specific rule.
You got /3 concepts.