Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable $user exists using Blade syntax.
Laravel
@[1]($user) <p>User exists.</p> @end[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @foreach instead of @if for condition checks.
Forgetting to close the directive with @endif.
✗ Incorrect
The Blade directive @if is used to check conditions like if a variable exists.
2fill in blank
mediumComplete the code to loop through the $users array and display each user's name.
Laravel
@[1]($users as $user) <p>{{ $user->name }}</p> @end[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @for instead of @foreach for arrays.
Not using the correct variable syntax inside the loop.
✗ Incorrect
The @foreach directive is used to loop over arrays or collections in Blade templates.
3fill in blank
hardFix the error in the Blade loop to correctly iterate 5 times.
Laravel
@[1] ($i = 0; $i < 5; $i++) <p>Iteration {{ $i }}</p> @end[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @foreach for numeric loops.
Forgetting to close the loop with @endfor.
✗ Incorrect
The @for directive is used for traditional for loops with initialization, condition, and increment.
4fill in blank
hardFill both blanks to create a Blade loop that iterates over $items and checks if each $item is active.
Laravel
@[1]($items as $item) @[2]($item->active) <p>{{ $item->name }} is active.</p> @end[2] @end[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @for instead of @foreach for arrays.
Using @foreach instead of @if for conditions.
✗ Incorrect
Use @foreach to loop over items and @if to check a condition inside the loop.
5fill in blank
hardFill all three blanks to create a Blade loop that iterates 3 times, checks if the index is even, and displays the index.
Laravel
@[1] ($i = 0; $i < 3; $i++) @[2] ($i % 2 == 0) <p>Index {{ $i }} is even.</p> @endif @end[3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @foreach for numeric loops.
Forgetting to close the loop with @endfor.
Using @endif to close the loop instead of @endfor.
✗ Incorrect
Use @for for the loop, @if for the condition, and close the loop with @endfor.