title: What is relationship count condition in WhereHas Laravel
body: <p>I am having a difficulty understanding the relationship count condition in <a href="http://laravel.com/docs/4.2/eloquent#querying-relations">WhereHas</a>. The docs page does not have discussion about it but <a href="http://laravel.com/api/4.1/Illuminate/Database/Eloquent/Builder.html#method_whereHas">API page</a> talks about it. Quote from API.</p>
  
  <blockquote>
    <p>Builder|Builder whereHas(string $relation, Closure $callback, string
    $operator = '>=', int $count = 1)</p>
    
    <p>Add a relationship count condition to the query with where clauses.</p>
  </blockquote>
  
  <p><strong>Example</strong></p>
  
  <p>A <code>Resource</code> Model has Many to Many relation to <code>ResourceCategory</code></p>
  
  <pre><code>public function categories()
  {
      return $this-&gt;belongsToMany('ResourceCategory', 'resource_category_mapping');
  }
  </code></pre>
  
  <p><strong>Relationship condition in Has</strong></p>
  
  <p>The relationship condition in <a href="http://laravel.com/api/4.1/Illuminate/Database/Eloquent/Builder.html#method_has">Has</a> is working as expected.</p>
  
  <pre><code>Resource::has('categories', '&gt;', 1)-&gt;get()
  //this return all resources which have more than one catgories
  </code></pre>
  
  <p><strong>Relationship condition in WhereHas</strong></p>
  
  <p>The relationship condition in WhereHas is not working as expected. I am sure I have misunderstood it.</p>
  
  <pre><code>Resource::whereHas('categories', function ( $query){
              $query-&gt;whereIn('resource_category_id', [1, 2, 4]);
          }, '&gt;', 1)-&gt;get()
  </code></pre>
  
  <p>The above code should return resources which whose categories belong to either of [1, 2, 4] and the resource has more than one categories. But it is not.</p>
  
  <p><strong>Question</strong></p>
  
  <p>Kindly explain the relationship condition in WhereHas, may be providing an example would be much helpful.</p>