title: How to get last rows with group by in Laravel eloquent
body: <p>I want to find the last rows with <code>groupBy</code> in Laravel. I've table like below:</p>
  
  <pre><code>id name ad_id
  1  a    1
  2  b    2
  3  a    2
  4  c    1
  </code></pre>
  
  <p>I want the result to be grouped by <code>ad_id</code> like below:</p>
  
  <pre><code>id name ad_id
  3  a    2
  4  c    1
  </code></pre>
  
  <p>My current query:</p>
  
  <pre><code>MyTable::groupBy('ad_id')-&gt;orderBy('id', 'desc')-&gt;get();
  </code></pre>
  
  <p>which returns the first two rows.
  So, what should be my eloquent query?</p>