簡體   English   中英

Laravel {{ auth()->user()->plan['name'] }} 如果為空

[英]Laravel {{ auth()->user()->plan['name'] }} if empty

我希望如果有人有計划,它會顯示{{ auth()->user()->plan['name'] }}

但如果此人沒有計划,則應該是“演示”之類的文本

我怎樣才能做到這一點?

您可以使用ifternary

 {{ auth()->user()->plan['name'] ?  auth()->user()->plan['name'] : 'Demo' }}

或者

@if (auth()->user()->plan['name'])
    {{  auth()->user()->plan['name'] }}
@else
   Demo
@endif

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM