Use double curly braces {{ }} to show variables safely (it escapes HTML).
Directives start with @ and control logic like loops and conditions.
Examples
Shows the value of the variable $name safely inside HTML.
Laravel
{{ $name }}
Shows text only if the condition is true.
Laravel
@if($age >= 18)
You are an adult.
@endif
Loops over a list of users and shows each user's name.
Laravel
@foreach($users as $user)
<p>{{ $user->name }}</p>
@endforeach
Includes another Blade file called header.blade.php here.
Laravel
@include('header')
Sample Program
This Blade template shows a welcome message with the user's name. It checks if the user is an adult or minor and shows a message. Then it lists user names in a bullet list.
Laravel
@php
$name = 'Alice';
$age = 20;
$users = [
(object)['name' => 'Bob'],
(object)['name' => 'Carol']
];
@endphp
<h1>Welcome, {{ $name }}!</h1>
@if($age >= 18)
<p>You are an adult.</p>
@else
<p>You are a minor.</p>
@endif
<h2>User List:</h2>
<ul>
@foreach($users as $user)
<li>{{ $user->name }}</li>
@endforeach
</ul>
OutputSuccess
Important Notes
Always use {{ }} to print variables to avoid security risks from raw HTML.
Blade directives like @if, @foreach make your templates easy to read and write.
You can write plain PHP inside @php ... @endphp blocks if needed.
Summary
Blade syntax mixes PHP and HTML simply and safely.
Use {{ }} to show variables and @directives for logic.
Blade helps keep your web pages clean and easy to maintain.
Practice
(1/5)
1. Which Blade syntax is used to safely display a variable's value in a view?
easy
A. Using PHP echo tags like
B. Using single curly braces like { $variable }
C. Using double curly braces like {{ $variable }}
D. Using square brackets like [ $variable ]
Solution
Step 1: Identify Blade syntax for output
Blade uses double curly braces {{ }} to display variables safely by escaping HTML.
Step 2: Compare options
Only Using double curly braces like {{ $variable }} uses {{ $variable }}, which is the correct Blade syntax.
Final Answer:
Using double curly braces like {{ $variable }} -> Option C
Quick Check:
Safe variable display = {{ $variable }} [OK]
Hint: Remember: {{ }} is for safe variable output in Blade [OK]
Common Mistakes:
Using single braces which is invalid in Blade
Using raw PHP echo instead of Blade syntax
Confusing square brackets with Blade syntax
2. Which of the following is the correct Blade directive to start a conditional statement?
easy
A. @if(condition)
B. #if(condition)
C. if(condition):
D. @@if(condition)
Solution
Step 1: Recall Blade directive syntax
Blade uses directives starting with @ for control structures like conditionals.
Step 2: Identify correct conditional start
The correct syntax to start an if statement is @if(condition).
Final Answer:
@if(condition) -> Option A
Quick Check:
Blade if start = @if(condition) [OK]
Hint: Blade directives always start with @ symbol [OK]
Common Mistakes:
Using # instead of @ for directives
Using raw PHP if syntax inside Blade
Double @ signs which are for escaping
3. What will be the output of this Blade snippet if $name = 'Alice'?
Step 1: Identify correct conditional syntax for object property
Blade @if treats object boolean properties like $user->email_verified as truthy if verified.
Step 2: Evaluate each snippet's logic and syntax
Snippet A with @if($user->email_verified) correctly shows only verified users. Snippet B uses array syntax $user[email_verified] invalid on objects. Snippet C with @if($user->email_verified == true has syntax error (missing closing )). Snippet D uses = true (assignment), always true, shows all users.
Final Answer:
Option A -> Option A
Quick Check:
Object property truthy check [OK]
Hint: Use == for comparison, not = which assigns [OK]
Common Mistakes:
Using = instead of == in conditions
Using array syntax on objects
Forgetting closing parenthesis in @if conditions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.