title: Laravel Eloquent - distinct() and count() not working properly together
body: <p>So I'm trying to get the number of distinct pids on a query, but the returned value is wrong.</p>
  
  <p>This is what I try to do:</p>
  
  <pre><code>$ad-&gt;getcodes()-&gt;groupby('pid')-&gt;distinct()-&gt;count()
  </code></pre>
  
  <p>what returns the value "2", while the value it should return, should be "1".</p>
  
  <p>As a workaround, I'm doing this:</p>
  
  <pre><code>count($ad-&gt;getcodes()-&gt;groupby('pid')-&gt;distinct()-&gt;get())
  </code></pre>
  
  <p>what works fine and returns "1"</p>
  
  <p>Is there any rule where count and distinct cannot be on the same query? I find the workaround kind of "heavy", I would like to make the original query work :(</p>