I have a gallery of products laid out like this:
<div class="row no-gutters bg-light">
@foreach ($products as $product)
<!-- Column 1 -->
<div class="col-6 @if(count($products) === 1 || 4 || 5) card-w-bg @endif">
<div class="row no-gutters">
<!-- Column 1-a -->
<div class="col-6 showcase-col">
<div class="overlay"></div>
<div class="showcase-hero showcase-text">
<h2 class="card-title mb-4"><a href="">{{ $product->name }}</a></h2>
<h3 class="card-subtitle text-muted">{{ $product->details }}</h3>
<h4 class="mb-3">{{ $product->presentPrice() }}</h4>
<p class="card-text mb-4 d-none d-md-block">Lorem ipsum dolor sit amet consectetur adipisicing elit. A
The if statement needs to add the dark gray bg to items 1, 4 and 5 only.
If 1,4 and 5 are the products ids you can:
@if($product->id === 1 || $product->id === 4 || $product->id === 5) card-w-bg @endif
If 1,4 and 5 are the place in the loop:
@if($loop->iteration === 1 || $loop->iteration === 4 || $loop->iteration === 5) card-w-bg @endif
The way you have applied if condition is wrong, correct way is showb below:
@if(count($products) == 1 || count($products) == 4 || count($products) == 5) //change over here
//some code
@endif
Therefore, replace
<div class="col-6 @if(count($products) === 1 || 4 || 5) card-w-bg @endif">
to the following:
<?php $reqArr=[1,4,5]; ?>
<div class="col-6 @if(in_array(count($products),$reqArr)) card-w-bg @endif">
You might want to use the loop variable created by laravel's foreach so you can access the current index instead of using count
on $products
that will always return the same value. So you can do something like this:
<div class="col-6 {{ $loop->index == 0 || 3 || 4 ? 'card-w-bg' : ''}}">