Documentation Index
Fetch the complete documentation index at: https://kawax.biz/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
Blade is the simple yet powerful templating engine included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates. All Blade templates are compiled into plain PHP and cached, so Blade adds virtually zero overhead to your application. Blade template files use the.blade.php extension and are stored in the resources/views directory.
Displaying data
Display data passed to a Blade view by wrapping the variable in double curly braces:Blade’s
{{ }} syntax automatically passes output through PHP’s htmlspecialchars function to prevent XSS attacks.Unescaped output
Use the{!! !!} syntax when you need to render raw HTML without escaping:
Coexisting with JavaScript frameworks
When your JavaScript framework also uses curly brace syntax, prefix the expression with@ to tell Blade to leave it alone:
@ symbol, and {{ name }} is sent as-is to the browser for your JavaScript framework to render.
If you want to compare Blade with Livewire, Inertia, and SPA-style setups, see Frontend.
Blade directives
Conditionals
@unless to express “if not”:
@isset and @empty:
Authentication directives
Switch statements
Loops
Blade provides convenient directives for every common loop type:@break and @continue to control loop execution:
The loop variable
Inside@foreach loops, the $loop variable gives you useful information about the current iteration:
| Property | Description |
|---|---|
$loop->index | Current loop index (zero-based) |
$loop->iteration | Current iteration count (one-based) |
$loop->remaining | Remaining iterations |
$loop->count | Total number of items |
$loop->first | Whether this is the first iteration |
$loop->last | Whether this is the last iteration |
$loop->even | Whether this is an even iteration |
$loop->odd | Whether this is an odd iteration |
$loop->depth | Nesting depth of the current loop |
$loop->parent | Parent loop variable when nested |
Comments
Blade comments are never included in the rendered HTML:Layouts
Component-based layouts
Using Blade components is the recommended approach for building layouts in modern Laravel applications. First, create a layout component:Template inheritance
The classic approach uses@extends, @section, and @yield:
Defining the parent layout:
@parent lets you append to the parent’s @section content instead of replacing it.Including sub-views
Use@include to embed another Blade view. All variables available in the parent view are automatically available in the included view:
CSRF protection in forms
HTML forms in theweb routes file that send POST, PUT, PATCH, or DELETE requests must include the @csrf directive:
PUT, PATCH, or DELETE requests from an HTML form, use the @method directive:
See CSRF protection for origin verification, token fallback behavior, and AJAX header strategies (
X-CSRF-TOKEN / X-XSRF-TOKEN).Summary
Displaying data
Displaying data
{{ $variable }} for escaped output, {!! $variable !!} for raw (unescaped) output.Conditionals
Conditionals
@if, @elseif, @else, @endif, @unless, @isset, @empty, @auth, @guest.Loops
Loops
@for, @foreach, @forelse, @while with $loop variable for iteration metadata.Layouts
Layouts
Component-based layouts (
<x-layout> with {{ $slot }}) or template inheritance (@extends, @section, @yield).Sub-views
Sub-views
@include to embed reusable view partials.