Answer the question
In order to leave comments, you need to log in
How to build a request in laravel?
Hello.
Thanks in advance for any answer!
have CATEGORIES
CATEGORIES(one) have PRODUCTS(many)
PRODUCTS(many) have STORE(one)
STORE(one) has ADDRESS_CITY(many)
CATEGORIES=>PRODUCTS=>STORE=>ADDRESS_CITY
you must select all CATEGORIES that have:
- there is at least 1 PRODUCT // has
- this PRODUCT must have a SHOP in which the ADDRESS exists in Moscow
. I tried to build a query, it does not work, the documentation has only the hasManyThrough method
that jumps through 1 table, but there are more of them. Or I even blunt)
Help build a request!
Another question: if I have 1 million products and 1000 stores, will the request be processed normally or do I need to look for other FEATURES:
- save id_city in json in PRODUCTS
- save id_city in json in SHOP
Thank you all!
Answer the question
In order to leave comments, you need to log in
$result = Category::where('on_off', 1)
->has('product')
->whereHas('product', function ($query) use ($city_one) {
$query->where('on_off' , 1)
->whereHas('shop', function ($query) use ($city_one) {
$query->where('on_off', 1)
->whereHas('shop_map_point', function ($query) use ($ city_one) {
$query->where('city_id', $city_one->id);
});
});
})
->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question