M
M
MaxSemenov2021-10-01 14:58:58
Laravel
MaxSemenov, 2021-10-01 14:58:58

How to get products of child categories?

You need to get a list of child categories with their products and filtered by domains,
This is not how it works

$productCategory = ProductCategory::where('slug','jga-party-fuer-maenner')->firstOrFail();
   $categories = ProductCategory::with('products.domains')->whereHas('products.domains', function($q){
                    $q->whereIn('name',['site.de','site.at']);
                })
                ->select('product_categories.*')
                ->descendantsOf($productCategory->id)
                ->toTree($productCategory->id);

It should look like
Category
- Product 1
- Product 2
, etc.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question