title: How to merge two Laravel Query Builder Objects into one Query Builder Object
body: <p>I have two <code>Illuminate\Database\Query\Builder</code> or <code>Illuminate\Database\Eloquent\Builder</code> objects, each for the same table/model.</p>
  <p>I need to merge these two objects into a single one so that the resultant Builder has all the <code>wheres, joins, group by's, etc</code> of both the objects</p>
  <p>As an example, suppose</p>
  <pre><code>$query1 = MyModel::where('column_name', $value);
  $query2 = MyModel::where('some_other_column_name', $someOtherValue)-&gt;join(...some conditions);
  </code></pre>
  <p>I need a resultant query which contains both the where clauses and the join (in this example).</p>
  <pre><code>$resultantQuery = mergeQueries($query1, $query2);
  
  // Equivalent to
  $resultant = MyModel::where('column_name', $value)-&gt;where('some_other_column_name', $someOtherValue)-&gt;join(...some conditions);
  </code></pre>
  <p>The resultant can be either of</p>
  <ol>
  <li>a new Builder object</li>
  <li>the <code>$query1</code> object itself with <code>$query</code> merged into it. (Preferred)</li>
  </ol>
  <p>What I <strong>don't</strong> want</p>
  <ul>
  <li>Merging them using union</li>
  <li>Getting the results of each query and then merging them</li>
  </ul>
  <p>PS, my true goal is to merge a <code>Illuminate\Database\Eloquent\Builder</code> object into a <code>Illuminate\Database\Query\Builder</code> object. I get both of these objects from plugins, so I cannot add all the where's and joins on a single object and don't wish to make the resultant query more complex that it already is</p>