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

Maged's avatar
Level 6

how to count category->products which are related to the order

I have four tables Order, Category, Product, Order_Product

each product belongs to a category each order has many products

i save the order products in order_product table,

now in orderResource i want to have number of order->products in each category so OrderResource should have

data 
[
{
 category_name: 'something',
productsCount: 3,
},
{
category_name: 'somethingelse',
productsCount: 2
}
]

how to do so ?

0 likes
2 replies

Please or to participate in this conversation.