title: Query builder when() method producing wrongly conditioned query
body: <p>I posted what I think is a Laravel bug (<a href="https://github.com/laravel/framework/issues/39398" rel="nofollow noreferrer">https://github.com/laravel/framework/issues/39398</a>) but it was closed because I'm not 100% that it's really a bug. Could someone else tell me whether this behaviour is erraneous?</p>
  <p>I have the following piece of code:</p>
  <pre><code>$user=251;
  $description='created';
  Activity::when($user, function ($query, $user) {
      return $query-&gt;where('causer_id', $user)
      -&gt;orWhere(function($query) use ($user) {
          $query-&gt;where('subject_id', $user)
          -&gt;where('subject_type', &quot;App\\User&quot;);
      });
  })-&gt;when($description, function ($query, $description) {
      return $query-&gt;where('description', $description);
  });
  </code></pre>
  <p>Logically I think it should produce a query that return all rows that has the correct user and the correct description but I get all rows with that user regardless of description.</p>
  <p>The code above produces this sql query:</p>
  <pre><code>select * from activity_log where causer_id = '251' or (subject_id = '251' and subject_type = 'App\User') and description = 'created'
  </code></pre>
  <p>...whereas I think it should produce:</p>
  <pre><code>select * from activity_log where (causer_id = '251' or (subject_id = '251' and subject_type = 'App\User')) and (description = 'created')
  </code></pre>
  <p>To put it short: Shouldn't the when() function put parentheses around it's returned result not to affect other parts of the query? Is it a bug that it doesn't?</p>