How to get a nested list of a child by Parent id?

TIGER

I am using baum to get nested list of categories. I have a case where I only want to get a child of few parent id. I have used static function getNestedList("name", null, "   ") which gives me all categories nested list separated by space. I want the same response but only for few parent categories.

I tried below code to get my list with where clause but it only works with the first result. I have multiple parent_id and I need the each child listed in an array with space operator.

$node = Category::where('name', '=', 'Some category I do not want to see.')->first();

$root = Category::where('name', '=', 'Old boooks')->first();
var_dump($root->descendantsAndSelf()->withoutNode($node)->get());

QUESTION UPDATE

The issue I was facing to get descendants and self categories list using Baum was just because of wrong entry in my database. I am sorry for that. Now, I am getting my category list using descendantsAndSelf() but the issue is how to created the nested list with $seperator ?

I tried to toHierarchy() but it only return nested collection. I did not found any function which provides nested list like the function getNestedList("text", null, "   ");. Please help me on this.

TIGER

UPDATED ANSWER

As per my updated question, Below is my answer what I actually want to do.

To get list of Descendants with parent I have used below function.

public function getSubcategory($id) {
    $node = $this->where('id', $id)->with('children')->first();
    $descendant = $node->getDescendantsAndSelf()->toArray();
    return $this->CreateNestedList("text", $descendant, null, "-");
}

And to create nested loop I have used the same logic of the function getNestedList(). I have created new function inside my model file as below.

public function CreateNestedList($column, $data, $key = null, $seperator = ' ') {
        $key = $key ?: $this->getKeyName();
        $depthColumn = $this->getDepthColumnName();

        return array_combine(array_map(function($node) use($key) {
          return $node[$key];
        }, $data), array_map(function($node) use($seperator, $depthColumn, $column) {
          return str_repeat($seperator, $node[$depthColumn]) . $node[$column];
        }, $data));
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the ID of a child when mouseover parent

From Dev

How to stop nested list overlapping parent list?

From Dev

jQuery - Get path of nested list's child

From Dev

Get child list of parent process in C

From Dev

How to get the parent div id from the anchor child

From Dev

Python: create a nested dictionary from a list of parent child values

From Dev

get child id from parent javascript onclick

From Dev

Rails 4 nested shallow routes: how to get parent id in child controller?

From Dev

Supposed to get the child but somehow gets the parent ID

From Dev

How to validate existence of parent id in child model in Rails for nested attributes

From Dev

How to get List of Parent Entities with Child Count In Nhibernate QueryOver

From Dev

How to find a child with the parent's id in Laravel?

From Dev

Is it possible to get the gameobject nested child from parent with script?

From Dev

Create a nested parent child list in Java 8

From Dev

How to get the id of a very short child process if the parent is known?

From Dev

How to get child table rows using parent table ID?

From Dev

How to get the ID of a child when mouseover parent

From Dev

get the id of parent tr for a child td

From Dev

jQuery - Get path of nested list's child

From Dev

How to get list of specific child instances from list of parent instances?

From Dev

Python: create a nested dictionary from a list of parent child values

From Dev

How to validate existence of parent id in child model in Rails for nested attributes

From Dev

How to get ID Parent from Child ID when i have className of the Parents JQuery/JS

From Dev

How to find parent id by click on child id and then child id by getting parent id via jquery

From Dev

How can I get the list of all the items nested(hierarchy) within the item based on parent-child relationship?

From Dev

get the parent and child id of js tree

From Dev

Combine Parent and Child Lists into a single nested Parent List

From Dev

how to get the list of child nodes for each treeview parent

From Dev

C# How to Get list of Ids from Parent-Child list

Related Related

  1. 1

    How to get the ID of a child when mouseover parent

  2. 2

    How to stop nested list overlapping parent list?

  3. 3

    jQuery - Get path of nested list's child

  4. 4

    Get child list of parent process in C

  5. 5

    How to get the parent div id from the anchor child

  6. 6

    Python: create a nested dictionary from a list of parent child values

  7. 7

    get child id from parent javascript onclick

  8. 8

    Rails 4 nested shallow routes: how to get parent id in child controller?

  9. 9

    Supposed to get the child but somehow gets the parent ID

  10. 10

    How to validate existence of parent id in child model in Rails for nested attributes

  11. 11

    How to get List of Parent Entities with Child Count In Nhibernate QueryOver

  12. 12

    How to find a child with the parent's id in Laravel?

  13. 13

    Is it possible to get the gameobject nested child from parent with script?

  14. 14

    Create a nested parent child list in Java 8

  15. 15

    How to get the id of a very short child process if the parent is known?

  16. 16

    How to get child table rows using parent table ID?

  17. 17

    How to get the ID of a child when mouseover parent

  18. 18

    get the id of parent tr for a child td

  19. 19

    jQuery - Get path of nested list's child

  20. 20

    How to get list of specific child instances from list of parent instances?

  21. 21

    Python: create a nested dictionary from a list of parent child values

  22. 22

    How to validate existence of parent id in child model in Rails for nested attributes

  23. 23

    How to get ID Parent from Child ID when i have className of the Parents JQuery/JS

  24. 24

    How to find parent id by click on child id and then child id by getting parent id via jquery

  25. 25

    How can I get the list of all the items nested(hierarchy) within the item based on parent-child relationship?

  26. 26

    get the parent and child id of js tree

  27. 27

    Combine Parent and Child Lists into a single nested Parent List

  28. 28

    how to get the list of child nodes for each treeview parent

  29. 29

    C# How to Get list of Ids from Parent-Child list

HotTag

Archive