3 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
如果 1,4 和 5 是產(chǎn)品 ID,您可以:
@if($product->id === 1 || $product->id === 4 || $product->id === 5) card-w-bg @endif
如果 1,4 和 5 是循環(huán)中的位置:
@if($loop->iteration === 1 || $loop->iteration === 4 || $loop->iteration === 5) card-w-bg @endif

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊
如果條件錯(cuò)誤,您申請(qǐng)的方式,正確的方式如下所示:
@if(count($products) == 1 || count($products) == 4 || count($products) == 5) //change over here
//some code
@endif
因此,更換
<div class="col-6 @if(count($products) === 1 || 4 || 5) card-w-bg @endif">
到以下幾點(diǎn):
<?php $reqArr=[1,4,5]; ?>
<div class="col-6 @if(in_array(count($products),$reqArr)) card-w-bg @endif">

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可能希望使用由 laravel 的 foreach 創(chuàng)建的循環(huán)變量,以便您可以訪問(wèn)當(dāng)前索引,而不是使用count
on$products
將始終返回相同的值。所以你可以做這樣的事情:
<div class="col-6 {{ $loop->index == 0 || 3 || 4 ? 'card-w-bg' : ''}}">
- 3 回答
- 0 關(guān)注
- 214 瀏覽
添加回答
舉報(bào)