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

thoba's avatar
Level 1

Multiple Models into one predefined query

Hi forum,

I've got multiple Models which each are part of one big Product.

Lets say i've got the following Models: Product (Contains the basics of ID, price, category id, etc.) ProductStatus (Whether it's active or not) ProductDescription (Name, Description, Language ID (Multiple rows for one product, but differentiated by the language id)) ProductStock (Keeps track of the stock)

Since i'm going to use products a LOT of places, it would be much easier to maintain ONE class, than editing queries in all kinds of controllers.

In the end, i'd like to be able to call something like $product->stock, and get the stock count, which i get from ProductStock in relation to the product ID etc.

How would you go about making such a query, and where? As a service, package or what is your recommendation with your experience?

Hope you can help.

  • Thomas
0 likes
1 reply
sr57's avatar

@thoba

There is no standard way of doing this, but of course it's a good thing (for maintenance, ... ) to code functionality in one place and to split your business logic.

Writing a package is not the answer to your question, the use of a package is to re-use code between projects.

So YES you should write (a) common class(es) and use them where you need. To use them you can call it where you want or write it as a service to make it available as other services.

Please or to participate in this conversation.