When you build a website, you want pages that look great and display live information—like a visitor's name or a list of blog posts. Writing plain HTML files cannot do that on its own, while mixing long PHP tags inside HTML quickly gets messy. That is where Laravel Blade Templates come to the rescue.

What is Blade? (The Smart Fill-in-the-Blank Sheet)

Think of a Blade template like a printed party invitation card with blank lines. The layout, colors, and borders stay the same for every guest, and you only fill in the guest's name on the blank line. Blade files end with .blade.php and live inside your project's resources/views/ folder.

Printing Variables Safely with {{ }}

To show a dynamic value in Blade, you wrap it in double curly braces. Laravel automatically protects your page from unsafe characters (called auto-escaping), so visitors cannot accidentally break your layout.

<!-- resources/views/welcome-user.blade.php -->
<h1>Hello, {{ $name }}!</h1>
<p>Welcome to your first Laravel page.</p>

From your routes/web.php file, you pass the $name value into that view like handing a filled form to a printer:

<?php
// Send the variable $name into welcome-user.blade.php
Route::get('/hello/{name}', function ($name) {
    return view('welcome-user', ['name' => $name]);
});

Making Decisions with @if and @else

Sometimes you want to show a different message depending on a condition—just like a shop sign that says "Open" during the day and "Closed" at night. Blade gives you clean @if and @else directives:

@if($isLoggedIn)
    <p>Welcome back! Here is your dashboard.</p>
@else
    <p>Please sign in to continue.</p>
@endif

Repeating Items with @foreach

Instead of copying and pasting the same HTML list item ten times, you can let @foreach loop through a list for you:

<ul>
@foreach($fruits as $fruit)
    <li>{{ $fruit }}</li>
@endforeach
</ul>

Sharing One Master Layout

Every page on a website usually shares the same navigation bar and footer. With @extends and @section, you write that shared shell once in layouts/app.blade.php and plug each page's unique content into it.

3 Things to Remember

  • Where they live: Blade templates use the .blade.php extension inside resources/views/.
  • Safe output: Use {{ $variable }} to display data safely without messy PHP echo tags.
  • Clean logic: Use @if, @foreach, and @extends to keep your HTML readable and reusable.