英文:
Blade Tag Condition in one line Laravel
问题
Here's the translated code without the HTML tags:
{{ $user->status ? 'Active' : 'Not Active' }}
This code should display "Active" if the $user->status
is truthy and "Not Active" if it's falsy.
英文:
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
答案1
得分: 1
只需简单地放入要呈现的位置。
英文:
Just simply put into where you want to rendered.
<span class="badge bg-{{ $user->status ? 'success' : 'danger' }}">{{ $user->status ? 'Active' : 'Not Active' }}</span>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论