Hi I used Laravel relationships with many to many pivot tables without problems but i can't get around the logic i need to write to create a relation between 3 models using 2 pivot tables to execute a query like the one below:
select * from product
left join product_to_category on product_to_category.product_id = product.product_id
left join category on product_to_category.category_id = category.category_id
left join category_to_brand on category_to_brand.category_id = category.category_id
left join brand on brand.brand_id = category_to_brand.brand_id
where brand.key = 'furniture-hire-uk'
and category.slug = 'chair-hire'
the table structure is as follows:
product product id some more feilds
category category id some more feilds
brand brand_id key some more feilds
product_to_category product_id category_id
category_to_brand category_id brand_id
Product::leftJoin()->leftJoin()->where()->where()->get([columns you need])
- have you tried that? – Jarek Tkaczyk