From f98feb398cde33d577acac0d8fc74c0d5d25207b Mon Sep 17 00:00:00 2001 From: Bart Hijmans Date: Fri, 18 Sep 2020 09:34:32 +0200 Subject: [PATCH] Made a protected variable for $parentRelation --- src/NestableCollection.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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); } } }