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?