baum
baum copied to clipboard
getNestedList() scope support will be nice
:+1:
Is it possible to exclude some element with child nodes from getNestedList() results?
* root
** child
*** child child
When you edit "child" element (see above tree) then you don't want to allow selecting current tree element ("child") and "child child" - it should be allowed to exclude them from select box easily.
Something like:
NavItem::withoutNode($navItem)->getNestedList('name', 'id', '-')
I used:
array_diff_key(NavItem::getNestedList('name', 'id', '-'), $navItem->descendantsAndSelf()->lists('name', 'id'))
Is there a better solution?
+1
Something like Category::whereAccountId($account_id)->getNestedList('title') would be greatly appreciated;
+1
even better:
public static function getScopedNestedList($column, $key = null, $seperator = ' ', $company_logged) {
$instance = new static;
$key = $key ?: $instance->getKeyName();
$depthColumn = $instance->getDepthColumnName();
$nodes = $instance->where('company_id', $company_logged)
->orderBy('lft', 'asc')
->get()
->toArray();
foreach ($nodes as $key => $value) {
$name = str_repeat($seperator, $value['depth']) . $value['name'];
$array[] = array('id'=>$value['id'], 'name'=>$name, 'depth'=>$value['depth']);
}
return $array;
}