Reputation: 253
I have the some tables: Orders
, Products
, ProductsImages
.
I try to get all orders:
$orders = Orders::with("Products")->with("images")->get();
So relationship is:
Orders.product_id = Products.id
Products.id = ProductsImages.product_id
I want to connect these tables in one request through Order model.
Upvotes: 2
Views: 42
Reputation: 163768
You want to use many-to-many relation between orders
and products
and one-to-many relation between products
and productsImages
Just setup these relationships as described in documentation and load data using nested eager loading:
Orders::with('products.productsImages')->get();
Upvotes: 1