In my database I have Categories, and they can have child categories. Categories also have products. Ex:
Category
Sub-Category 1
Product 1
Sub-Sub-Category 1
Product 2
Product 3
Category Model
public function childs()
{
return $this->hasMany('App\Category', 'parent_id', 'id');
}
public function products()
{
return $this->belongsToMany('App\Products');
}
My question is if I do $Category->products, I want it to give me all the products. If I do $Sub-Sub-Category-1, it gives me product 2 and product 3. Thanks for the help.