0
0
Laravelframework~10 mins

Control structures (@if, @foreach, @for) in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aforeach
Bwhile
Cfor
Dif
Attempts:
3 left
💡 Hint
Common Mistakes
Using @foreach instead of @if for condition checks.
Forgetting to close the directive with @endif.
2fill in blank
medium

Complete 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'
Afor
Bif
Cforeach
Dwhile
Attempts:
3 left
💡 Hint
Common Mistakes
Using @for instead of @foreach for arrays.
Not using the correct variable syntax inside the loop.
3fill in blank
hard

Fix 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'
Aforeach
Bfor
Cwhile
Dif
Attempts:
3 left
💡 Hint
Common Mistakes
Using @foreach for numeric loops.
Forgetting to close the loop with @endfor.
4fill in blank
hard

Fill 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'
Aforeach
Bif
Cfor
Dwhile
Attempts:
3 left
💡 Hint
Common Mistakes
Using @for instead of @foreach for arrays.
Using @foreach instead of @if for conditions.
5fill in blank
hard

Fill 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'
Aforeach
Bif
Cfor
Dwhile
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.