Reputation: 1952
I have 4 models connected with hasMany relations as below:
Brand -> hasMany -> Categories -> hasMany -> subCategories -> hasMany -> products
I want to retrieve the categories that their subcategories have one or more products.
I tried querying relationship existence with has
and/or whereHas
but no luck.
Thanx for your advice,
Upvotes: 0
Views: 26
Reputation: 18916
Using has()
dot annotation, should do the trick for you.
$categories = Category::has('subCategories.products')->get();
Upvotes: 1