3 回答
TA贡献1770条经验 获得超3个赞
实际上,这就是您要执行的操作:
@if($accounts->count())
@foreach($accounts as $showaccounts)
<div class="list-item" data-id="item-11"><span class="w-40 avatar circle blue"> <img src="{{ $showaccounts->image }}" alt="."></span>
<div class="list-body"><a href="app.message.php" class="item-title _500">{{ $showaccounts->username }}</a>
</div>
</div>
@endforeach
@else
<div class="no-result">
<div class="p-4 text-center">No Results</div>
</div>
@endif
但是如果你像下面这样构造它会更好:
@forelse($accounts as $account)
<div class="list-item" data-id="item-11"><span class="w-40 avatar circle blue"> <img src="{{ $account->image }}" alt="."></span>
<div class="list-body">
<a href="app.message.php" class="item-title _500">{{ $account->username }}</a>
</div>
</div>
@empty
<div class="no-result">
<div class="p-4 text-center">No Results</div>
</div>
@endforelse
循环变量通常采用复数形式,例如:accounts-account。
TA贡献1802条经验 获得超5个赞
在您的代码中,您检查了元素属性。但你想检查表。因此,您可以尝试获取元素集合的计数
@if( $showaccounts->count() )
@foreach($accounts as $showaccounts)
<div class="list-item" data-id="item-11"><span class="w-40 avatar circle blue"> <img src="{{ $showaccounts->image }}" alt="."></span>
<div class="list-body"><a href="app.message.php" class="item-title _500">{{ $showaccounts->username }}</a>
</div>
</div>
@endforeach
@else
<div class="no-result">
<div class="p-4 text-center">No Results</div>
</div>
@endif
- 3 回答
- 0 关注
- 228 浏览
添加回答
举报