title: Laravel. Broken query
body: <p>I have got an error that I don't understand. I've got a <code>users</code> table and  <code>firsts, seconds, thirds</code> tables. </p>
  
  <p>I wrote a query which should select all users, where status is approved in <code>firsts, seconds, thirds</code> tables (depending on status). </p>
  
  <p>At the moment I have user which has <code>firsts and seconds</code> status <code>pending</code>, but query still finds him. Could you explain what am I doing wrong? What way would you recommend to use in this case? Here is my query:</p>
  
  <pre><code>$users = User::whereIn('users.status', array(2, 3))
              -&gt;leftJoin('firsts', 'firsts.user_id', '=', 'users.id')
              -&gt;leftJoin('seconds', 'seconds.user_id', '=', 'users.id')
              -&gt;leftJoin('thirds', 'thirds.user_id', '=', 'users.id')
              -&gt;where(function($query) {
                $query-&gt;where('users.status', 2);
                $query-&gt;where('firsts.status', 'approved');
                $query-&gt;where('seconds.status', 'approved');
              })
              -&gt;orWhere(function($query) {
                $query-&gt;where('users.status', 3);
                $query-&gt;where('users.stripe_active', '1');
                $query-&gt;orWhere('users.subscription_ends_at', '!=', 'NULL');
                $query-&gt;where('firsts.status', 'approved');
                $query-&gt;where('seconds.status', 'approved');
                $query-&gt;where('thirds.status', 'approved');
              })
              -&gt;groupBy('users.id')
              -&gt;select('users.id')
              -&gt;get();
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>So I still can't find a solution. Here is users id's result array: <code>[3,6,7]</code></p>
  
  <p>User with id 3:</p>
  
  <pre><code>Firsts status = 'pending',
  Seconds status = 'approved',
  Thirds status = 'approved'.
  </code></pre>
  
  <p>User with id 6:</p>
  
  <pre><code>Firsts status = 'pending',
  Seconds status = 'pending',
  Thirds status = 'approved'.
  </code></pre>
  
  <p>User with id 7: </p>
  
  <pre><code>Firsts status = 'approved',
  Seconds status = 'approved',
  Thirds status = 'approved'.
  </code></pre>
  
  <p>As you can see <code>user</code> with <code>id 3</code> and <code>6</code> should not be in array.</p>