I need help in defining relationships for the following tables
product
id
name
modifier
id
name
modifier_items
id
modifier_id
name
price
modifier_product
id
modifier_id
product_id
One Product may have multiple Modifiers
Please help me define a relationship in Laravel that outputs the expected results
Expected Result in Product Model
i.e Product::with([...])->get()
id: 1,
name: "Product name", // (Product name)
modifiers: [
{
id: 1, // modifier_id
name: "some name 1",
items: [
{
id: 1, // modifier_item_id,
name: "modifier name",
price: 10
},
{
id: 2, // modifier_item_id,
name: "modifier name",
price: 20
}
]
},
{
name: "some name 2",
items: [] // Collection of Modifier items
},
]