/** * After mode was saved we're building node path * * @param Tree $model */ public function saved(Tree $model) { if ($model->{$model->getTreeColumn('path')} === '') { // If we just save() new node $model->{$model->getTreeColumn('path')} = $model->getKey() . '/'; DB::table($model->getTable())->where($model->getKeyName(), '=', $model->getKey())->update(array($model->getTreeColumn('path') => $model->{$model->getTreeColumn('path')})); } }
/** * Check if node is sibling for roots in collection * * @param Tree $node Tree node * @param Collection $roots Collection of roots * * @return bool */ private function siblingOfRoot(Tree $node, Collection $roots) { return (bool) $roots->filter(function ($item) use($node) { return $node->isSibling($item); })->first(); }