I understand your desired result, but I would like to know more about what you are doing behind the scenes.
Are the entities (product, product_images) Eloquent models? If they are, take a look at how these queries are built; you may be surprised at how intelligently it builds queries. Also, take a look at eager loading for more info.
If you would like to, or need to, use a raw expression, it would be helpful to know your target db. What your describing is a pretty simple join.
No matter the means you use, if you are using a relational database you will need to loop through your results to convert normalized data to nested data as you are describing. Given that fact, I encourage you to let Eloquent do the work.
Great, thanks! Eager loading was exactly I was looking for.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community