Blade Directive | Description | Example Usage |
---|---|---|
{{ $var }} | Echoes and escapes a variable | {{ $name }} |
{!! $var !!} | Echoes a variable without escaping | {!! $html !!} |
@if / @elseif / @else / @endif | Standard conditional blocks | @if($logged) Hi @else Login @endif |
@unless / @endunless | Runs block if the condition is false | @unless($mode) ... @endunless |
@isset / @endisset | Runs block if variable is set | @isset($var) ... @endisset |
@empty / @endempty | Runs block if variable is empty | @empty($array) ... @endempty |
@auth / @endauth | Runs if user is authenticated | @auth Welcome! @endauth |
@guest / @endguest | Runs if user is not authenticated | @guest Please login! @endguest |
@env / @endenv | Runs block for specific environment | @env('local') Local only @endenv |
@production / @endproduction | Runs block in production environment | @production Live! @endproduction |
@hasSection / @endif | Checks if a layout section exists | @hasSection('sidebar') ... @endif |
@sectionMissing / @endif | Checks if section does not exist | @sectionMissing('footer') ... @endif |
@session / @endsession | Runs block if session value exists | @session('status') {{ $value }} @endsession |
@context / @endcontext | Runs block if context value exists | @context('canonical') {{ $value }} @endcontext |
@switch / @case / @break / @default / @endswitch | Switch-case-like structure | @switch($val) @case(1) One @break @default Other @endswitch |
@for / @endfor | For loops, like in PHP | @for($i=0;$i<5;$i++) {{$i}} @endfor |
@foreach / @endforeach | Foreach loops, like in PHP | @foreach($users as $u) {{ $u }} @endforeach |
@forelse / @empty / @endforelse | Foreach with empty fallback | @forelse($items as $item) ... @empty No items! @endforelse |
@while / @endwhile | While loops, like in PHP | @while($cond) ... @endwhile |
@continue | Skip to next iteration in loop | @foreach ... @continue ... @endforeach |
@break | Breaks out of a loop | @for ... @break ... @endfor |
@php / @endphp | Raw PHP code inside Blade | @php $a = 1; @endphp |
@use() | Import PHP classes/functions/constants | @use('App\Models\User') @use(function App\Helpers\easy, 'easyFn') |
@include | Includes a Blade view | @include('shared.menu') |
@includeIf | Includes a view if it exists | @includeIf('view.name') |
@includeWhen / @includeUnless | Includes view conditionally | @includeWhen($ok, 'view.ok') / @includeUnless($ok, 'view.no') |
@includeFirst | Includes the first existing view from a list | @includeFirst(['custom','default']) |
@each | Includes a view for each item in an array | @each('view.row', $items, 'item') |
@once / @endonce | Runs block only once per rendering | @once ... @endonce |
@push / @endpush&@stack | For pushing content to named stacks (e.g. scripts or styles) | @push('scripts')<script>...</script>@endpush...@stack('scripts') |
@prepend / @endprepend | Like push, but adds to start of stack | @prepend('css') ... @endprepend |
@pushOnce / @endPushOnce & @prependOnce / @endPrependOnce | Like above, but only once | @pushOnce('js') ... @endPushOnce |
@component / @endcomponent | Manually render a Blade component | @component('components.alert',['type' => 'error']) Message @endcomponent |
@slot / @endslot | Defines a slot for a component | @slot('title') Title @endslot |
@props | Import component's attributes | @props(['title']) |
@verbatim / @endverbatim | Block ignored by Blade parsing | @verbatim {{ this will not be rendered }} @endverbatim |
{{-- comment --}} | Blade comment (not included in HTML) | {{-- This is a comment --}} |
@class([...]) | Dynamic classes for HTML tags | <div @class(['active' => $ok])> |
@style([...]) | Dynamic styles for HTML tags | <span @style(['font-weight: bold' => $imp])> |
@checked($cond) | Addscheckedif condition is true | <input @checked($user->active) /> |
@selected($cond) | Addsselectedif condition is true | <option @selected($val==1)>Test |
@disabled($cond) | Addsdisabledif condition is true | <button @disabled($err)>OK |
@readonly($cond) | Addsreadonlyif condition is true | <input @readonly($onlyView)> |
@required($cond) | Addsrequiredif condition is true | <input @required($must)> |
Note: There are also Blade directives for layouts (@extends, @section, @yield, @parent, @show), working with components (), and using slots. This cheatsheet covers all the major and most used Blade directives in Laravel 12, serving as a handy reference for your projects, documentation, or as a quick reminder during development.