title: Laravel 5 – querying items by many-to-many related model
body: <p>I've got a following many-to-many relation:</p>
  
  <p><code>attendees - attendee_tag - tag</code></p>
  
  <p>Now I want to filter attendees based on some tag value, so I've created this solution, which works well:</p>
  
  <pre><code>$attendees = Attendee::whereHas('tags', function ($q) {
      $q-&gt;where([
          ['attendee_tag.tag_id', '=', '6'],
          ['attendee_tag.value_string', '=', 'Summer ticket']
  })-&gt;with(['tags' =&gt; function($q) {
          $q-&gt;select('tags.id', 'value_type', 'attendee_tag.value_string', 'attendee_tag.value_int');
  }])-&gt;paginate($pagination);
  </code></pre>
  
  <p>But I can't figure out, how to filter attendees based on more than 1 tag ... I've tried this, but it doesn't work:</p>
  
  <pre><code>$attendees = Attendee::whereHas('tags', function ($q) {
      $q-&gt;where([
          ['attendee_tag.tag_id', '=', '6'],
          ['attendee_tag.value_string', '=', 'Summer ticket']
      ])-&gt;where([
          ['attendee_tag.tag_id', '=', '13'],
          ['attendee_tag.value_string', '=', 5]
      ]);
  })-&gt;with(['tags' =&gt; function($q) {
      $q-&gt;select('tags.id', 'value_type', 'attendee_tag.value_string', 'attendee_tag.value_int');
  }])-&gt;paginate($pagination);
  </code></pre>
  
  <p>Any help would be highly appreciated! :)</p>