Bird
0
0

Given this Laravel controller code snippet:

medium📝 component behavior Q13 of 15
Laravel - Request and Response
Given this Laravel controller code snippet:
public function store(Request $request) {
    $validated = $request->validate([
        'age' => 'required|integer|min:18'
    ]);
    return $validated['age'];
}

What will be the output if the request sends age=20?
AValidation error: age is required
BValidation error: age must be at least 18
Cnull
D20
Step-by-Step Solution
Solution:
  1. Step 1: Understand validation rules

    Field 'age' must be present, an integer, and minimum 18.
  2. Step 2: Check input value

    Input age=20 meets all rules: present, integer, and >=18.
  3. Step 3: Determine output

    Validation passes, so $validated['age'] returns 20.
  4. Final Answer:

    20 -> Option D
  5. Quick Check:

    Valid input returns value [OK]
Quick Trick: Valid input passes and returns validated data [OK]
Common Mistakes:
  • Assuming validation error for valid input
  • Confusing min rule with max
  • Expecting null when validation passes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes