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?
phpcn_u15822017-05-16 16:49:08
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