Originally published on laravel.learnio.dev — part of the Laravel best practices course. View this lesson on the original site.
In this lesson
Blade is Laravel's templating engine. It lets you keep HTML readable while adding simple server-side logic for rendering data.
How Blade fits after controllers
In the previous lesson, controllers handled incoming requests. Blade is usually the next step:
- route matches URL,
- controller gathers data,
- controller returns a Blade view,
- Blade renders final HTML.
flowchart LR
A[Browser request] --> B[Route]
B --> C[Controller action]
C --> D[view with data]
D --> E[Rendered HTML response]
Create and render your first Blade view
Create resources/views/home.blade.php:
<h1>Welcome</h1>
<p>Laravel Blade is working.</p>
Return it from a route or controller:
Route::get('/home', function () {
return view('home');
});
view('home') maps to resources/views/home.blade.php.
Pass data from controller to Blade
Controller action:
public function index()
{
$user = ['name' => 'Stuart', 'plan' => 'Pro'];
return view('dashboard', ['user' => $user]);
}
Blade view resources/views/dashboard.blade.php:
<h1>Hello, {{ $user['name'] }}</h1>
<p>Current plan: {{ $user['plan'] }}</p>
{{ }} escapes output by default, which helps prevent XSS.
Layouts and sections for reusable page structure
Base layout resources/views/layouts/app.blade.php:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>@yield('title', 'My App')</title>
</head>
<body>
<main>
@yield('content')
</main>
</body>
</html>
Child view resources/views/profile.blade.php:
@extends('layouts.app')
@section('title', 'Profile')
@section('content')
<h1>Your profile</h1>
@endsection
This keeps shared page chrome in one place and each screen focused on its own content.
Blade directives you will use daily
Conditionals:
@if ($isAdmin)
<p>Admin tools enabled.</p>
@else
<p>Standard user view.</p>
@endif
Loops:
@forelse ($projects as $project)
<li>{{ $project->name }}</li>
@empty
<li>No projects yet.</li>
@endforelse
Includes:
@include('partials.flash')
Practical guardrails
- Keep heavy business logic in controllers, services, or models, not Blade.
- Use
{{ $value }}for user-facing data; avoid{!! $value !!}unless content is trusted and sanitised. - Prefer small partials and layouts over one large template.
You now have the full path from request to HTML: route, controller, and Blade view.
From Laravel best practices — What is Laravel?