Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Great, thanks! Eager loading was exactly I was looking for.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

TimHas timhas Joined 25 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.