Reputation: 207
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>
Upvotes: 1
Views: 11964
Reputation: 381
You can put HTML code in PHP variable as a string and that variable should be placed in {!! !!}
braces.
Example:
{!! $text !!}
Upvotes: 4
Reputation: 5824
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.
Upvotes: 5
Reputation: 7617
In blade you could do something like this:
<td class="nowrap">
@if($order->status=='0')
<button class="btn btn-danger">Inactive</button>';
@else
<button class="btn btn-success">Active</button>';
@endif
</td>
Upvotes: 2
Reputation: 2541
<td class="nowrap">
@if($order->status=='0')
<button class="btn btn-danger">Inactive</button>
@else
<button class="btn btn-success">Active</button>
@endif
</td>
or
<td class="nowrap">
<button class="btn btn-{{($order->status=='0') ? 'danger' : 'success'}}">{{($order->status=='0') ? 'Inactive' : 'Active'}}</button>
</td>
Upvotes: 2