/** * Set hierarchy information for new item * * @param CategoryItem $item item object * @return void */ protected function setHierarchy(CategoryItem $item) { // 이미 존재하는 경우 hierarchy 정보를 새로 등록하지 않음 try { $item->ancestors()->attach($item->getKey(), [$item->getDepthName() => 0]); } catch (\Exception $e) { return; } if ($item->{$item->getParentIdName()}) { $model = $this->createItemModel(); /** @var CategoryItem $parent */ $parent = $model->newQuery()->find($item->{$item->getParentIdName()}); $this->linkHierarchy($item, $parent); } }