title: Display distinct values on a laravel blade view
body: <p>I have a prices table that stores the date which a product cost was stored. There is a relationship between the product &amp; price model which works very well by returning the collection. I want to display a table with a date &amp; product name as the columns, then display the <strong>DISTINCT</strong> dates &amp; the corresponding product cost on each row. Below is my blade view code and what the table looks like</p>
  
  <p>view - code</p>
  
  <pre><code>&lt;table class="table table-striped"&gt;
  &lt;thead&gt;
      &lt;th&gt;Date&lt;/th&gt;
      @if (isset($products) &amp;&amp; !empty($products))
  
          @foreach ($products as $product) 
              &lt;th&gt;{{ ucwords($product-&gt;name) }}&lt;/th&gt;
  
  &lt;/thead&gt;
  
  &lt;tbody&gt;
          @foreach ($product-&gt;prices as $price)            
          &lt;tr&gt;
              &lt;td&gt;{{ $price-&gt;date }}&lt;/td&gt;
              &lt;td&gt;{{ $price-&gt;cost }}&lt;/td&gt;
          &lt;/tr&gt;
          @endforeach
  
          @endforeach
      @else
          Product price is not available
      @endif
  
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>browser-view
  <a href="https://i.stack.imgur.com/k0EYk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k0EYk.png" alt="enter image description here"></a></p>
  
  <p>Changing my code by ending the first foreach loop, gives me something close to what i want but only the cost for the last product is displayed</p>
  
  <p>alternative code</p>
  
  <pre><code>&lt;table class="table table-striped"&gt;
  &lt;thead&gt;
      &lt;th&gt;Date&lt;/th&gt;
      @if (isset($products) &amp;&amp; !empty($products))
  
          @foreach ($products as $product) 
              &lt;th&gt;{{ ucwords($product-&gt;name) }}&lt;/th&gt;
          @endforeach
  
  &lt;/thead&gt;
  
  &lt;tbody&gt;
          @foreach ($product-&gt;prices as $price)            
          &lt;tr&gt;
              &lt;td&gt;{{ $price-&gt;date }}&lt;/td&gt;
              &lt;td&gt;{{ $price-&gt;cost }}&lt;/td&gt;
          &lt;/tr&gt;
          @endforeach
  
      @else
          Product price is not available
      @endif
  
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Browser-view
  <a href="https://i.stack.imgur.com/mPivO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mPivO.png" alt="enter image description here"></a></p>
  
  <p>How do i display all of my product cost values for each date in the format of the last picture?</p>