Bird
0
0

Given this controller method:

medium📝 component behavior Q4 of 15
Laravel - Controllers
Given this controller method:
public function show($id) {
    return view('user.profile', ['userId' => $id]);
}

What will be passed to the view when show(5) is called?
ANo data is passed to the view
BThe integer 5 directly
CA string 'user.profile' only
DAn array with key 'userId' and value 5
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the return statement

    The method returns a view with an array ['userId' => $id].
  2. Step 2: Substitute the argument value

    Calling show(5) sets $id = 5, so array is ['userId' => 5].
  3. Final Answer:

    An array with key 'userId' and value 5 -> Option D
  4. Quick Check:

    Data passed to view [OK]
Quick Trick: View data is passed as an associative array [OK]
Common Mistakes:
  • Assuming only the value is passed, not array
  • Confusing view name with data
  • Thinking no data is passed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes