Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to display a variable in Blade template.
Laravel
<p>[1]</p> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including the curly braces inside the blank.
Using PHP echo syntax inside Blade.
✗ Incorrect
In Blade, variables are displayed using double curly braces with the variable name inside, like {{ $name }}. Here, the blank is inside the double braces, so just the variable name with $ is needed.
2fill in blank
mediumComplete the code to write an if statement in Blade.
Laravel
@if([1]) <p>Welcome back!</p> @endif
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ sign before variable.
Writing just the variable name without comparison.
✗ Incorrect
Blade if statements use PHP expressions. To check if $user is true, write $user == true inside the parentheses.
3fill in blank
hardFix the error in the Blade loop syntax.
Laravel
@foreach($items as [1]) <li>{{ $item }}</li> @endforeach
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding $ before the loop variable in the foreach statement.
Using the collection name instead of the item variable.
✗ Incorrect
In Blade foreach loops, the variable after 'as' should not have a $ sign. So use 'item' not '$item'.
4fill in blank
hardFill both blanks to create a Blade component with a slot and a variable.
Laravel
<x-alert type=[1]> [2] </x-alert>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the string attribute value.
Using $message without curly braces.
✗ Incorrect
The component attribute 'type' needs a string in quotes, so "error" is correct. To display the slot variable, use Blade's double curly braces with $message inside.
5fill in blank
hardFill all three blanks to write a Blade directive for a loop with a condition.
Laravel
@foreach($users as [1]) @if([2]->active) <p>[3]->name</p> @endif @endforeach
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ in the foreach variable.
Omitting $ inside Blade expressions.
Mixing variable names inconsistently.
✗ Incorrect
In the foreach, the variable after 'as' is 'user' without $. In the if condition, use 'user->active' (no $). Inside the paragraph, use $user->name with $ sign and curly braces.