如何在HTML div类上使用laravel blade编写if

o7jaxewo  于 2023-04-13  发布在  其他
关注(0)|答案(1)|浏览(126)
<!-- Wrapper for slides -->
  <div class="carousel-inner">
   @foreach($product as $item)
   <!-- if id of item is one set to active if not to empty -->
   <div class="item {{$item['id']== 1?'active':''}}">
      <img src="la.jpg" alt="Chania">
      <div class="carousel-caption ">
        <h3>Los Angeles</h3>
        <p>LA is always so much fun!</p>
      </div>
      
   @endforeach
    </div>

我已经写了if conditoin,但它不工作,我想显示第一张幻灯片为活动

xzlaal3s

xzlaal3s1#

<!-- Wrapper for slides -->
  <div class="carousel-inner">
   @foreach($product as $item)
   <!-- if id of item is one set to active if not to empty -->
   <div class="item {{$item->id == 1 ? 'active': ''}}"> <!-- your id rendering caused it -->
      <img src="la.jpg" alt="Chania">
      <div class="carousel-caption ">
        <h3>Los Angeles</h3>
        <p>LA is always so much fun!</p>
      </div>
      </div>  <!-- closing div is needed as well -->
   @endforeach
</div>

相关问题