Search code examples
phpframeworkslaravel-5

How to echo html tag in blade of Laravel


I want to echo button to my blade but I don't know how to do. So, how to do that? Thanks you.

<td class="nowrap">{!! $order->status=='0'?
    @php
    echo '<button class="btn btn-danger">Inactive</button>';
    @endphp:
    @php
    echo '<button class="btn btn-success">Active</button>';
    @endphp
    !!}
</td>

Solution

  • You can do that using two ways first use if condition like below

    <td class="nowrap">
    @if( $order->status == '0' )
        <button class="btn btn-danger">Inactive</button>
    @else
        <button class="btn btn-success">Active</button>
    @endif
    </td>
    

    The second and proper way for use ternary operator on blade

    <td class="nowrap">
          {!! $order->status=='0' ? '<button class="btn btn-danger">Inactive</button>' : '<button class="btn btn-success">Active</button>' !!}
    </td>
    

    I hope the second way is perfect for used ternary operator on blade.