I have three models with following data:
Product
- id
- name
- description
Variant
- id
- colour
- type
- private
- product_id
Image
- url
- variant_id
So the relations are:
- Product hasMany Variants
- Variant hasMany Images
I need to get a collection of all the Variants, including the parent Product because I also need its name and including the images related to the Variant, with the conditions (on Variant) ->where('type', 'OPT') and ->where('private', false).
I tried to do it with a raw SQL query but I need to loop through Variant's images in the blade template, so I need a collection. How can I put all together without running too many queries?