I have eloquent relationships with category child
In category Model
public function products()
{
return $this->hasMany(Products::class, 'category', 'id');
}
public function sub() {
return $this->hasMany(SELF::class, 'parent_id')->withCount(['products'])->with('sub');
}
I would like to get in each category and child category has products count
Example Category A is the parent Category B and C are child of A category Category B has 3 products and category C 2 products
How to get product_count 5 (total of B and C category product count) in the A parent category when I call withCount()?
At the moment there is 0 count but child categories have product count.
Thank you so much for any idea!