我在表上使用 forelse 语句:
@forelse($message->content->suggestions as $suggestion)
<td>
@foreach ($message->content->suggestions as $suggestion)
<span class='badge badge-info'>{{($suggestion->reply->text)}}</span>
@endforeach
</td>
@empty
<em> - </em>
@endforelse
我的目标是检查表是否有称为建议的数据然后运行 foreach() 但是如果它是空的就显示“-”这是我第一次使用 forelse 并且想学习它:) 如果我不能这样做有人可以分享如何用 IF 语句来代替吗?
你能看出我做错了什么吗,如果我在没有建议的情况下打开一个表,我只会得到一个错误而不是“-”
给出错误的表如下所示:
"id" => "3d0ef00c-0edd-4d8b-ad1c-27e92e29c469"
"method" => "rcs"
"msisdn" => 64224603
"direction" => "mt"
"type" => "text"
"status" => "delivered"
"content" => "{"text":"Dial a number"}"
"suggestion_id" => null
"created_at" => 1591669329
"updated_at" => 1591669333
"deleted_at" => null
摇曳的蔷薇
慕容森