Модель «Категория» имеет отношение «hasMany», которое выглядит следующим образом.
Код: Выделить всё
public function children(){
return $this->hasMany(self::class, 'parent_id');
}
Код: Выделить всё
category_id | parent_id
------------------------
1 | NULL
2 | 1
3 | 2
4 | 3
5 | NULL
6 | 5
For example,
for category_id 1, should be selected lines with category_id [5, 6]
for category_id 2, should be selected lines with category_id [1, 5, 6]
for category_id 3, should be selected lines with category_id [1, 2, 5, 6]
for category_id 4, should be selected lines with category_id [1, 2, 3, 5, 6]
for category_id 5, should be selected lines with category_id [1, 2, 3, 4]
for category_id 6, should be selected lines with category_id [1, 2, 3, 4, 5]
Подробнее здесь: https://stackoverflow.com/questions/665 ... ry-builder