title: Get Taggables by common tags using rtconner/laravel-tagging
body: <p>I'm quite new to Laravel. I installed RConner's Laravel-Tagging plugin. It works fine.</p>
  
  <p>On a post page, I would like to get other posts (taggables) having similar tags.
  I know I can do it using sql joins and count (but not really how)</p>
  
  <p>I tried to add a scope-method to TaggableTrait, but I'm struggling with the joins.
  I'd like to know if there is a "Laravel's Way" of doing the magic. </p>
  
  <p>Thank you !</p>
  
  <p>Edit : 
  Actually, what I'm trying to achieve, is retrieving "taggables", ordered by number of common tags with the current content. </p>
  
  <p>I'm trying to add a scope-method to TaggableTrait such as :</p>
  
  <pre><code>public function scopeWithCommonTag($query, $tagNames)
  {
      $tagNames = TaggingUtil::makeTagArray($tagNames);
  
      $normalizer = \Config::get('tagging::normalizer');
      $normalizer = empty($normalizer) ? '\Conner\Tagging\TaggingUtil::slug' : $normalizer;
  
      $tagNames = array_map($normalizer, $tagNames);
  
      $query = $query-&gt;whereHas('tagged', function ($q) use ($tagNames) {
          $q-&gt;whereIn('tag_slug', $tagNames)-&gt;groupBy('taggable_id')-&gt;orderByRaw('count(*)');
      });
  }
  </code></pre>
  
  <p>The resulting query is :</p>
  
  <pre><code>select * from `contents` where (
      select count(*) from `tagging_tagged` 
      where `tagging_tagged`.`taggable_id` = `contents`.`id` 
      and `tagging_tagged`.`taggable_type` = ? 
      and `tag_slug` in (?, ?) 
      group by `taggable_id` 
      order by count(*)
  ) &gt;= 1
  </code></pre>
  
  <p>What I need is : </p>
  
  <pre><code>select * from `contents` where taggable_id in (
      select taggable_id,count(*) as common_tags 
      from `tagging_tagged` 
      where `tagging_tagged`.`taggable_id` = `contents`.`id` 
      and `tagging_tagged`.`taggable_type` = ? 
      and `tag_slug` in (?, ?) 
      group by `taggable_id` 
      order by common_tags desc
  ) limit 3;
  </code></pre>
  
  <p>Maybe something like this (I tried to use whereIn('id',closure) but obviously, it doesn't join the "tagged" table...</p>
  
  <pre><code>$query = $query-&gt;whereHas('tagged', function ($q) use ($tagNames) {
      $q-&gt;select(array('taggable_id',\DB::raw('count(*) as common_tags')))-&gt;whereIn('tag_slug', $tagNames)-&gt;groupBy('taggable_id')-&gt;orderByRaw('common_tags desc');
  });
  </code></pre>
  
  <p>It's a bit over my head. Any leads ?</p>