Bird
0
0

Consider this Laravel controller method:

medium📝 component behavior Q4 of 15
Laravel - Request and Response
Consider this Laravel controller method:
public function save(Request $request) {
    $data = $request->validate([
        'score' => 'required|numeric|min:50'
    ]);
    return $data['score'];
}

What will be returned if the request contains score=75?
AValidation error because 75 is not an integer
B75
Cnull
DAn exception due to missing field
Step-by-Step Solution
Solution:
  1. Step 1: Analyze validation rules

    The rule requires 'score' to be present, numeric, and at least 50.
  2. Step 2: Check input value

    The input 'score=75' is numeric and greater than 50, so it passes validation.
  3. Step 3: Return value

    The method returns the validated 'score' value, which is 75.
  4. Final Answer:

    75 -> Option B
  5. Quick Check:

    Input meets rules, returns value [OK]
Quick Trick: Validated numeric input returns value [OK]
Common Mistakes:
  • Confusing numeric with integer
  • Assuming validation fails for numbers above min
  • Expecting null or exceptions without missing data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes