title: Laravel groupBy Database query Builder not working
body: <p>I have this problem in a query using laravel groupBy, it simply return a groupBy error. I have read the documentation about this but can't really figure it out. I also read the same problem pointing that it is because of postgreSQL that I need to include all the columns in grouBy clause. I tried it but still it doesn't return the distinct values. Please help me with this. Below is my code. Thanks a lot.</p>
  
  <p><strong>Controller function</strong></p>
  
  <pre><code> public function index(){
      $purchases = Purchase::groupBy('purchase_order_id')-&gt;get();
      return view('purchases/purchases_crud', ['allPurchases' =&gt; $purchases]);
  }
  </code></pre>
  
  <p><strong>Table to query</strong>
  <a href="https://i.stack.imgur.com/h70xx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h70xx.png" alt="enter image description here"></a></p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>QueryException in Connection.php line 680:
  SQLSTATE[42803]: Grouping error: 7 ERROR: column "purchases.id" must appear
  in the GROUP BY clause or be used in an aggregate function
  LINE 1: select * from "purchases" group by "purchase_order_id"
  ^ (SQL: select * from "purchases" group by "purchase_order_id")
  </code></pre>