Bird
0
0

Identify the error in this Blade code:

medium📝 Debug Q14 of 15
Laravel - Views and Blade Templates
Identify the error in this Blade code:
@foreach($users as user)
  {{ $user->name }}
@endforeach
AMissing parentheses around $users
BMissing $ before user in the loop declaration
CIncorrect closing tag, should be @endfor
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check foreach syntax

    The variable in the loop must have a $ sign: @foreach($users as $user).
  2. Step 2: Verify other parts

    Parentheses are present, and closing tag is correctly @endforeach. So only missing $ is the error.
  3. Final Answer:

    Missing $ before user in the loop declaration -> Option B
  4. Quick Check:

    Variable names need $ in @foreach [OK]
Quick Trick: Always use $ before variables in @foreach [OK]
Common Mistakes:
  • Omitting $ before loop variable
  • Using wrong closing directive
  • Missing parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes