Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maxhas79's avatar

How to combine and retrieve values three tables

these are my three tables

-SALES -id -details

-SALES_ITEMS -sale_id -item_id

-ITEMS -id -name

After a sale done will push sale details to SALES table and push items of that sale to SALES_ITEMS table with 'id' from SALES table.item name are in ITEMS table..so i need to retrive datas from all three combined..like below:- {sales{[id:1, Details:..., sale_items:{[id:1 Item_id:1 item:{[id:1 name:item-name]}]}]}}

How to setup model and how to use that in controler? Ps: dont mind json typos..posting from mobile

0 likes
1 reply
Francismori7's avatar
  • Sale Model
    • Needs a items() relationship ($this->hasManyThrough)
  • SaleItem Model
  • Item Model

Review relationships and you'll be set to go.

Please or to participate in this conversation.