Challenge - 5 Problems
Blade Directive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What is the output of this Blade snippet?
Consider this Blade template code:
If
@if($user->isAdmin())Admin Access
@elseUser Access
@endif
If
$user->isAdmin() returns false, what will be rendered?Laravel
@if($user->isAdmin()) <p>Admin Access</p> @else <p>User Access</p> @endif
Attempts:
2 left
💡 Hint
Think about what the @else directive does when the condition is false.
✗ Incorrect
The @if directive checks the condition. Since $user->isAdmin() is false, the @else block runs, rendering
User Access
.📝 Syntax
intermediate1:30remaining
Which Blade directive correctly loops over an array?
You want to loop over
$items in Blade. Which option uses the correct directive syntax?Attempts:
2 left
💡 Hint
Blade uses a directive named after a common PHP loop for arrays.
✗ Incorrect
The correct directive to loop over arrays in Blade is @foreach. The others are invalid Blade directives.
🔧 Debug
advanced2:00remaining
What error does this Blade code cause?
Given this Blade snippet:
What error will occur when rendering?
@if($count > 0)Count is positive
@elseNo count
@endif
What error will occur when rendering?
Laravel
@if($count > 0) <p>Count is positive</p> @else <p>No count</p> @endif
Attempts:
2 left
💡 Hint
Check the placement of @else relative to @endif.
✗ Incorrect
The @else directive must be inside the @if block before @endif. Here, @else is after @endif, causing a syntax error.
❓ state_output
advanced1:30remaining
What is the output of this Blade component with @isset?
Given
What will be rendered?
$title = null; and this Blade code:@isset($title){{ $title }}
@elseDefault Title
@endisset
What will be rendered?
Laravel
@isset($title)
<h1>{{ $title }}</h1>
@else
<h1>Default Title</h1>
@endissetAttempts:
2 left
💡 Hint
Remember what @isset checks for in Blade.
✗ Incorrect
@isset checks if the variable is set and not null. Since $title is null, the @else block runs.
🧠 Conceptual
expert2:00remaining
Which Blade directive is used to include a child view and pass data?
You want to include a Blade view named
header and pass ['title' => 'Welcome'] to it. Which directive and syntax is correct?Attempts:
2 left
💡 Hint
Think about the directive that inserts a view and allows passing variables.
✗ Incorrect
@include inserts a child view and can pass data as an array. @component is for components, @yield is for sections, and @extends is for layout inheritance.