Laravel中一行的刀片标签条件

huangapple go评论61阅读模式
英文:

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>

huangapple
  • 本文由 发表于 2023年4月19日 17:25:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052858.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定