title: Laravel multiple whereHas criteria for relationship
body: <p>I have two tables - contacts and visits:</p>
  
  <p>Contacts Table</p>
  
  <pre><code>id    | name          
  ----- | -------
  1     | Joe
  2     | Sally
  </code></pre>
  
  <p>Visits Table</p>
  
  <pre><code>id    | contact_id | pathname  | referrer                
  ----- | -------    | -------   | -------
  1     | 1          | about     | google
  2     | 1          | pricing   | null
  3     | 1          | signup    | null
  4     | 2          | about     | null
  5     | 2          | signup    | null
  </code></pre>
  
  <p>Using eloquent, I would like to retrieve all <strong>contacts</strong> that have a both a <strong>pathname</strong> = 'signup' AND a <strong>referrer</strong> = 'google'.  </p>
  
  <p>What I've got so far is:</p>
  
  <pre><code>Contact::whereHas('visits', function($query) {
      $query-&gt;where('pathname','=','signup');
  })
  -&gt;orWhereHas('visits', function($query) {
      $query-&gt;where('referrer','=','google');
  })
  -&gt;get();
  </code></pre>
  
  <p>Which properly retrieves all contacts that have visited either the pricing OR signup page. </p>
  
  <p>However, this example would also retrieve <strong>Sally</strong> (from the example table above), since she visited signup, but was not referred by google. I need a way to only retrieve <strong>Joe</strong>, who was both referred by google and visited pricing.  </p>
  
  <p>Any ideas?  Thanks in advance!</p>