title: Laravel set first Bootstrap banner as Active
body: <p>I'm currently trying to loop through a bunch of banners saved on a database and I need to set the first banner as active. I've tried if($banner->first) {{ 'active' }} endif, but this doesn't seem to work for me as all items get set as active. I thought about setting the id to 1, but that would break if someone deleted the image with that id. Here's my code so far...</p>
  
  <p>Controller:</p>
  
  <pre><code>public function index()
  {
      //
      $banners = Banner::all();
      $pages = Page::all();
  
      return View::make('page')-&gt;with('banners', $banners, 'pages', $pages);
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;div id="mainCarousel" class="carousel slide" data-ride="carousel"&gt;
      &lt;div class="carousel-inner"&gt;
          @foreach($banners as $banner)
                  &lt;div class="item @if($banner-&gt;first()) {{ 'active' }} @endif"&gt;
                      &lt;img style="width: 100%; height: 500px" src="{{ $banner-&gt;image }}" alt="{{ $banner-&gt;alt }}"&gt;
                  &lt;/div&gt;
          @endforeach
      &lt;/div&gt;
  
      &lt;a class="left carousel-control" href="#mainCarousel" data-slide="prev"&gt;
          &lt;span class="glyphicon glyphicon-chevron-left"&gt;&lt;/span&gt;
      &lt;/a&gt;
      &lt;a class="right carousel-control" href="#mainCarousel" data-slide="next"&gt;
          &lt;span class="glyphicon glyphicon-chevron-right"&gt;&lt;/span&gt;
      &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have also tried $banners->first() as well as $banner->first() and get the same result.</p>
  
  <p>Any help on this would be greatly appreciated.</p>