I have a model Category
which has a manyToMany relation with itself:
public function parentcategories()
{
return $this->belongsToMany('App\Category', 'category_category', 'parent_category_id', 'category_id');
}
public function categories()
{
return $this->belongsToMany('App\Category', 'category_category', 'category_id', 'parent_category_id');
}
What is the simplest way to get all of the descendant Categories?
For example:
Cat1
-Cat2
-Cat3
--Cat4
--Cat5
---Cat6
Cat7
-Cat8
If I click Cat1
I want to get Cat2-6
, and if I click Cat3
I want to get Cat4-6
.