为什么我的雄辩查询在以后使用时会被覆盖?

I've encountered a very strange problem and I cannot find the cause of it. I was wondering if someone has encountered the same problem or if its a config problem.

Basically this was my block of code. Very simple stuff.

$productImages = App\ProductImage::where('product_id', $product->id)->orderBy("order", "asc");
$productImages_First = $productImages->first();
$productImages_All = $productImages->get();

If I performed a dump and die on $productImages_All then it would output the following:

Collection {
  #items: array:5
}

This has worked perfectly fine for months. I haven't touched this block of code at all.

However, I've noticed in the last week, that if I dump and die $productImages_All now, it will only return the first image and not all of them.

Collection {
  #items: array:1
}

It seems that the $productImages_First = $productImages->first(); is overwriting it. Is this standard behaviour? It would make complete sense if it was as its calling to the original eloquent query and I should create a separate one to get all of the images. However, what doesn't make sense is that this block of code has worked for months without a change and it has randomly broke.

I can fix this very quickly, I just want to see if I can get more clarity on what may cause this?

That's because when you call first method it modifies the Query/Builder object inside the Eloquent/Builder and sets limit property to 1, so you have to reset it's value before calling get method.

$productImages = App\ProductImage::where('product_id', $product->id)- 
>orderBy("order", "asc");
$productImages_First = (clone $productImages)->first();
$productImages_All = $productImages->get();

Or you can

$productImages = App\ProductImage::where('product_id', $product->id)- 
>orderBy("order", "asc");
$productImages_First = $productImages->first();
$productImages->getQuery()->limit=null;
$productImages_All = $productImages->get();