diff --git a/src/NestableCollection.php b/src/NestableCollection.php index 1a7ec3d..38cba8b 100644 --- a/src/NestableCollection.php +++ b/src/NestableCollection.php @@ -26,6 +26,8 @@ class NestableCollection extends Collection protected $childrenName = 'items'; + protected $parentRelation = 'parent'; + public function __construct($items = []) { parent::__construct($items); @@ -219,9 +221,9 @@ protected function setParentsRecursive(&$items, &$parent = null) { foreach ($items as $item) { if ($parent) { - $item->setRelation('parent', $parent); + $item->setRelation($this->parentRelation, $parent); } - $this->setParentsRecursive($item->items, $item); + $this->setParentsRecursive($item->{$this->childrenName}, $item); } } }