Recall & Review
beginner
What does the @if directive do in Laravel Blade templates?
The @if directive checks a condition and shows the enclosed HTML only if the condition is true. It's like asking a question: if this is true, then do something.
Click to reveal answer
beginner
How do you loop over a list of items in Blade using @foreach?
You use @foreach to repeat a block of HTML for each item in a list. It’s like saying: for each item in this list, show me this HTML with that item’s data.
Click to reveal answer
intermediate
What is the difference between @foreach and @for in Blade?
@foreach loops over each element in a collection or array, while @for loops a set number of times using a counter. Use @foreach for lists, and @for when you know how many times to repeat.
Click to reveal answer
intermediate
How do you write an @if-@elseif-@else structure in Blade?
You start with @if(condition), then add @elseif(another condition) for extra checks, and finish with @else for the default case. This lets you choose between multiple options.
Click to reveal answer
advanced
Can you use @continue and @break inside @foreach loops in Blade? What do they do?
Yes! @continue skips the current loop iteration and moves to the next item. @break stops the loop completely. They help control the loop flow like traffic signals.
Click to reveal answer
What will @if($user->isAdmin()) do in a Blade template?
✗ Incorrect
The @if directive checks the condition inside the parentheses. If $user->isAdmin() returns true, the content inside @if will show.
Which directive is best to loop over an array of posts in Blade?
✗ Incorrect
@foreach is designed to loop over each item in an array or collection, perfect for posts.
What does @break do inside a @foreach loop?
✗ Incorrect
@break immediately stops the loop, so no more items are processed.
How do you write a loop that runs exactly 5 times in Blade?
✗ Incorrect
@for is used when you want to repeat something a fixed number of times, like 5.
Which directive lets you check multiple conditions in Blade?
✗ Incorrect
The @if, @elseif, and @else directives let you check different conditions and choose what to show.
Explain how to use @if, @elseif, and @else in a Blade template to handle different conditions.
Think of it like asking questions one after another.
You got /4 concepts.
Describe the difference between @foreach and @for loops in Blade and when to use each.
One is for lists, the other for counting.
You got /4 concepts.