title: Laravel: how to express HAVING COUNT in eloquent
body: <p>How can I express this query in Laravel?</p>
  
  <pre><code>SELECT `projects_issues`.* FROM `projects_issues` 
  
   JOIN `projects_issues_tags` 
      ON `projects_issues_tags`.`issue_id` = `projects_issues`.`id` 
  
   JOIN `tags` 
      ON (`tags`.`id`  = `projects_issues_tags`.`tag_id`) 
  
  WHERE `project_id` = '1' 
  AND `tags`.`tag` IN('tagname1','tagname2')
  
  GROUP BY `projects_issues`.`id` 
  HAVING COUNT(DISTINCT `tags`.`tag`) = 2
  
  ORDER BY `projects_issues`.`updated_at` DESC
  </code></pre>
  
  <p>Right now my code is this. 
  `</p>
  
  <pre><code>$issues = \Project\Issue::with('tags');
  
          if ($tags || $sort_by != 'updated')
          {
              $issues = $issues
                  -&gt;join('projects_issues_tags', 'projects_issues_tags.issue_id', '=', 'projects_issues.id')
                  -&gt;join('tags', 'tags.id', '=', 'projects_issues_tags.tag_id');
          }
  
          $issues = $issues-&gt;where('project_id', '=', Project::current()-&gt;id);
  
          if ($tags)
          {
              $tags_collection = explode(',', $tags);
              $tags_amount = count($tags_collection);
  
              $issues = $issues-&gt;where_in('tags.tag', $tags_collection);//-&gt;get();
          }
  
          $issues = $issues
              -&gt;group_by('projects_issues.id')
              -&gt;order_by($sort_by_clause, $sort_order);
  
          if($tags &amp;&amp; $tags_amount&gt;1){
              $issues = $issues-&gt;having('count', '=', $tags_amount);
          }
  
          $issues = $issues-&gt;get(array('projects_issues.*'));
  </code></pre>
  
  <p>It returns this error: <code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'count' in 'having clause'</code></p>