I am trying to loop carousels with class “active” first item
here is my code
<div class="carousel-item active"> <div class="top-top"> <h4>some heading</h4> <iframe class="testimonial" width="100%" height="auto" src="https://www.youtube.com/embed/ynK2WIRg?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""> </iframe> </div> </div> @foreach($test as $tes) <div class="carousel-item"> <div class="top-top"> <h4>{{ $tes->name }}</h4> <iframe class="testimonial" width="100%" height="auto" src="https://www.youtube.com/embed/{{ $tes->file_name }}?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""> </iframe> </div> </div> @endforeach </div>
I trying to put active item in the loop too.
Advertisement
Answer
You can use $loop->iteration==1
as said in laravel blade doc inside the foreach:
@foreach($test as $tes) <div class="carousel-item @if($loop->iteration==1) active @endif"> <div class="top-top"> <h4>{{ $tes->name }}</h4> <iframe class="testimonial" width="100%" height="auto" src="https://www.youtube.com/embed/{{ $tes->file_name }}?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""> </iframe> </div> </div> @endforeach