title: Laravel / PHP - Embedding a Youtube video into an array of images
body: <p>I'm pretty new to PHP and Laravel, and I've got this landing page which shows images on the page body. </p>
  
  <p>My client wants to add a Youtube video instead of one of the images, and I'm not quite sure how to do so.</p>
  
  <p>I tried adding an if statement inside the foreach loop with a $counter which will show the embedded code when $counter is equal to $i, but I'm either doing it wrong or just don't know how to do it properly as nothing appears in the body, not the video nor the images..</p>
  
  <p>Would appreciate all the help, thanks!</p>
  
  <p>Here's the code:</p>
  
  <p>page.php :</p>
  
  <pre><code>public function index($path = "")
  {
  
      $data = $this-&gt;data;
  
          $images = [
              "images/portraits/1.jpg",
              "images/portraits/2.jpg",
              "images/portraits/3.jpg",
              "images/portraits/4.jpg"
          ];
  
      $data['images'] = $images;
      $counter = 0;
      $data['counter'] = $counter;
      return view($this-&gt;folderPath."main",$data);
  }
  </code></pre>
  
  <p>main.blade.php :</p>
  
  <pre><code>    @foreach($images as $i)
         &lt;?php if ($counter == 2)?&gt;
           &lt;?php if ($counter == 2) ?&gt;
              &lt;iframe
               width="560" height="315" 
              src="https://www.youtube.com/embed/VIDEOID? 
              rel=0&amp;amp;controls=0" 
              frameborder="0" allow="autoplay; encrypted-media" 
              allowfullscreen&gt;
              &lt;/iframe&gt;
          &lt;div class="cbp-item"&gt;
              &lt;a href="{{$i}}" class="cbp-caption cbp-lightbox"&gt;
                  &lt;div class="cbp-caption-defaultWrap"&gt;
                      &lt;img src="{{str_replace(".jpeg","_mini.jpeg",str_replace(".jpg","_mini.jpg",$i))}}" alt=""&gt;
                  &lt;/div&gt;
                  &lt;div class="cbp-caption-activeWrap cbp-gray"&gt;
                      &lt;div class="cbp-l-caption-alignCenter"&gt;
                          &lt;div class="cbp-l-caption-body"&gt;
                              &lt;i class="fa fa-expand enlarge-icon"&gt;&lt;/i&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/a&gt;
          &lt;/div&gt;
      @endforeach
  </code></pre>