Blade Tag Condition in one line Laravel

i have a code that show if condition in my blade like this

@if($user->status == "Y")
     <span class="badge bg-success">Active</span>
@else
     <span class="badge bg-danger">Not Active</span>
@endif

And i want it show in one line This if condition like this:

{{ $user->status ? Active : Not Active }}

but it doesn’t work with html span tag in it

I tried this code

{{ $user->status ?echo "<span class="badge bg-success">Active</span>" : echo "<span class="badge bg-danger">Not Active</span>" }}

And still it doesn’t work

>Solution :

Just simply put into where you want to rendered.

<span class="badge bg-{{ $user->status ? 'success' : 'danger' }}">{{ $user->status ? 'Active' : 'Not Active' }}</span>

Leave a Reply