Blade Directives

Blade Directives are shortcuts for common PHP control structures. These shortcuts provide a clean way of adding display logic to a view.

If Statements

You may construct if statements using the @if, @elseif, @else, and @endif directives. These directives function identically to their PHP counterparts:

@if (count($records) === 1)
    I have one record!
@elseif (count($records) > 1)
    I have multiple records!
    I don't have any records!

In addition to the conditional directives, the @isset and @empty directives may be used as convenient shortcuts for their respective PHP functions:

    // $records is defined and is not null...

    // $records is "empty"...


Blade provides simple directives for working with PHP's loop structures. Again, each of these directives functions identically to their PHP counterparts:

@for ($i = 0; $i < 10; $i++)
    The current value is {{ $i }}

@foreach ($users as $user)
    <p>This is user {{ $user }}</p>

When looping, a $loop variable will be available inside of the loop. The loop variable provides access to some useful bits of information such as the current loop index and whether this is the first or last iteration through the loop:

@foreach ($users as $user)
    @if ($loop->first)
        This is the first iteration.

    @if ($loop->last)
        This is the last iteration.

    <p>{{ $loop->index }}: {{ $user }}</p>


Blade also allows you to define comments in your views. However, unlike HTML comments, Blade comments are not included in the HTML returned by your application:

{{-- This comment will not be present in the rendered HTML --}}