Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

laravel从数据库中读取多个字段在视图中显示,如果字段为空则不显示,每个字段都加一个if判断吗?像下面这样:

@if ($user->name!=null)
<div>姓名:$user->name</div>
@endif

@if ($user->email!=null)
<div>邮箱:$user->email</div>
@endif

@if ($user->phone!=null)
<div>电话:$user->phone</div>
@endif

有没有其他写法?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
483 views
Welcome To Ask or Share your Answers For Others

1 Answer

其实这个你在后端(控制器判断更好,或者给一个默认值),你在视图上,体验很不好


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...