/** * Get primary key array for breadcrumbs * * @return array */ public function getBreadcrumbs() { if ($this->parent) { return array_merge($this->parent->getBreadcrumbs(), [$this->getKey()]); } return $this->ancestors->sort(function ($a, $b) { $aDepth = $a->pivot->{$this->getDepthName()}; $bDepth = $b->pivot->{$this->getDepthName()}; if ($aDepth == $bDepth) { return 0; } return $aDepth > $bDepth ? -1 : 1; })->push($this)->pluck($this->getKeyName())->toArray(); }
/** * Adds a node to this node * * @param NodeInterface $node nodes * * @return $this */ public function add(NodeInterface $node) { $this->rawNodes[$node->getNodeIdentifier()] = $node; $parentId = $node->getParentNodeIdentifier(); if ($parentId) { $parent = $this->rawNodes[$parentId]; $parent->addChild($node); $parent->setChildren($this->sort($parent->getChildren())); $node->setParent($this->rawNodes[$parentId]); } else { $this->treeNodes[$node->getNodeIdentifier()] = $node; } return $this; }