Laravel reads multiple fields from the database and displays them in the view. If the field is empty, it will not be displayed. Is it necessary to add an if judgment to each field?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 16:47:08
0
2
369

Laravel reads multiple fields from the database and displays them in the view. If the field is empty, it will not be displayed. Is it necessary to add an if judgment to each field? Like this:

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

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

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

Is there any other way to write it?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
phpcn_u1582

In fact, you are on the backend (the controller can better judge, or give a default value), and you are on the view, so the experience is very bad

PHPzhong

Write a Transformer to force data type conversion to string

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template