laravel blade php variable code example

Example 1: blade if

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

Example 2: laravel include with variable

@include('layouts.article', ['mainTitle' => "404, page not found", 'mainContent' => "sorry, but the requested page does not exist :("])

Example 3: blade set variable

@php ($i = 1)

Example 4: laravel 5.4 forelse

@forelse ($users as $user)
    
  • {{ $user->name }}
  • @empty

    No users

    @endforelse

    Example 5: laravel blade @if 3 varabile

    @if(is_null($key['p3']))
            {{--*/$p3 = $key['p3']/*--}}
        @else
            {{ 0 }}
        @endif
        @if(is_null($key['wabku']))
            {{--*/$wabku = $key['wabku']/*--}}
        @else
            {{ 0 }}
        @endif
        
            {{ number_format($p3 - $wabku,0,',','.') }}
        
        
        @php
        $p3 = $key['p3']
        @endphp

    Tags:

    Misc Example