Answer the question
In order to leave comments, you need to log in
Access to many through relationships. How to get close?
There is a system with categories, products, sellers, brands, sales. Almost all models have relationships with each other - mostly many to many. However, with some samples, frankly speaking, there is a gag. For example, in categories, display the number of sellers of goods. Salespeople are present only in sales and are even related to products through a many-to-many relationship. I tried to get through hasManyThrough('App\Sale', 'App\Good','id','good_d'), but it displays one sale (it's not clear which one) and that's it. And there can be hundreds of them for one product and category. Help tie it together. Thank you!
I have already displayed the number of products in the categories, i.e. the goods themselves are displayed without problems
Answer the question
In order to leave comments, you need to log in
Models (and relations, respectively) are needed when you are going to work with them as with models , i.e. change, save, use other "magic". But if you need to get data that you are not going to change (display, calculate, use in other queries), then use the usual Query Builder for this ( https://laravel.com/docs/8.x/queries ) and do any join'y, whichever you like.
Keep in mind that not every query can be (or conveniently) done with Eloquent, especially when it comes to aggregation functions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question