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

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

我希望如果有人有计划,它就会被展示 {{ auth()->user()->plan['name'] }}

但如果此人没有计划,则应该是 "Demo"

这样的文字

我该怎么做?

您可以使用 ifternary

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

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