Bird
0
0

Consider this Blade snippet:

medium📝 component behavior Q5 of 15
Laravel - Views and Blade Templates
Consider this Blade snippet:
@include('profile', ['user' => $user])

If $user has a property name = 'Alice', what will {{ $user->name }} inside profile.blade.php display?
Auser
BAlice
CError: Undefined variable
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Passing data to sub-view

    The array passes $user to the profile view as a variable named $user.
  2. Step 2: Accessing $user->name in profile view

    Since $user is passed correctly, {{ $user->name }} outputs 'Alice'.
  3. Final Answer:

    Alice -> Option B
  4. Quick Check:

    Passed variable accessible in sub-view = Alice [OK]
Quick Trick: Pass variables as array to access in included view [OK]
Common Mistakes:
  • Not passing variable causes undefined error
  • Expecting variable name as string output
  • Confusing variable scope in Blade

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes