/** * 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(); }