/** * Handle the command. */ public function handle() { $model = $this->builder->getModel(); /* * If the builder has an entries handler * then call it through the container and * let it load the entries itself. */ if ($handler = $this->builder->getTreeOption('entries')) { app()->call($handler, ['builder' => $this->builder]); return; } $entries = $this->builder->getTreeEntries(); /* * If the entries have already been set on the * tree then return. Nothing to do here. * * If the model is not set then they need * to load the tree entries themselves. */ if (!$entries->isEmpty() || !$model) { return; } /* * Resolve the model out of the container. */ $repository = $this->builder->getTreeRepository(); /* * If the repository is an instance of * TreeRepositoryInterface use it. */ if ($repository instanceof TreeRepositoryInterface) { $this->builder->setTreeEntries($repository->get($this->builder)); } }
/** * Set the tree entries. * * @param \Illuminate\Support\Collection $entries * @return $this */ public function setTreeEntries(\Illuminate\Support\Collection $entries) { if (!$this->getFieldType()) { $entries = $entries->sort(function ($a, $b) { return array_search($a->id, $this->getSelected()) - array_search($b->id, $this->getSelected()); }); } return parent::setTreeEntries($entries); }