title: Laravel reuse of variable with nested relationships does not keep original data
body: <p>While trying to reuse a variable in two different classes, the first class affects the data of the variable passed to the second class.</p>
  <p><strong>Example of problem</strong>:</p>
  <pre><code>class SampleA
  {
      public function __construct($products)
      {
          // Has 3 rows since it's the first class being called
          unset($products[0]);
      }
  }
  
  class SampleB
  {
      public function __construct($products)
      {
          // Should have 3 rows, only has 2
          unset($products[1]);
      }
  }
      
  $collection = \App\Models\Products::with('barcodes')-&gt;with('stock')-&gt;limit(3)-&gt;get(); // 3 rows for test purposes
  
  $first = new SampleA($collection);
  $second = new SampleB($collection);
  
  // The $collection should have 3 rows and only has 1
  print_r($collection); 
  </code></pre>
  <hr />
  <p><strong>What have I tried without success</strong>:</p>
  <p>Use of <code>collect</code>:</p>
  <pre><code>$collection = \App\Models\Products::with('barcodes')-&gt;with('stock')-&gt;limit(3)-&gt;get();
  $copyCollectionFirst = collect($collection);
  $copyCollectionSecond = collect($collection);
  
  $first = new SampleA($copyCollectionFirst);
  $second = new SampleB($copyCollectionSecond);
  </code></pre>
  <p>Use of <code>clone</code>:</p>
  <pre><code>$collection = \App\Models\Products::with('barcodes')-&gt;with('stock')-&gt;limit(3)-&gt;get();
  $copyCollectionFirst = clone $collection;
  $copyCollectionSecond = clone $collection;
  
  $first = new SampleA($copyCollectionFirst);
  $second = new SampleB($copyCollectionSecond);
  </code></pre>
  <p>Use of <code>replicate</code>:</p>
  <pre><code>$collection = \App\Models\Products::with('barcodes')-&gt;with('stock')-&gt;limit(3)-&gt;get();
  $copyCollectionFirst = [];
  $copyCollectionSecond = [];
  
  foreach ($collection as $row)
  {   
      $copyCollectionFirst[] = $row-&gt;replicate();
      $copyCollectionSecond[] = $row-&gt;replicate();
  }
  
  $copyCollectionFirst = collect($copyCollectionFirst);
  $copyCollectionFirst = collect($copyCollectionSecond);
  
  $first = new SampleA($copyCollectionFirst);
  $second = new SampleB($copyCollectionSecond);
  </code></pre>
  <p>Whatever I do in the <code>SampleA class</code>, it will affect the <code>SampleB class</code> variable data.</p>
  <hr />
  <p><strong>What works</strong>:</p>
  <p>Query multiple times the database:</p>
  <pre><code>$collectionFirst = \App\Models\Products::with('barcodes')-&gt;with('stock')-&gt;limit(3)-&gt;get();;
  $collectionSecond = \App\Models\Products::with('barcodes')-&gt;with('stock')-&gt;limit(3)-&gt;get();;
  
  $first = new SampleA($collectionFirst);
  $second = new SampleB($collectionSecond);
  </code></pre>
  <p>Is there any way to avoid query DB multiple times? In my case this is important, since I might have thousands of records &amp; use it more than 2 times.</p>