title: How to insert child into parent as json from database in Laravel/PHP?
body: <p>Here's my database table:</p>
  
  <pre><code>id   name               icon            parent_id
  1    Account Settings   fa fa-cog       0
  2    Support            fa fa-wrench    0
  3    FAQ                fa fa-question  2
  4    Contact            fa fa-phone     2
  </code></pre>
  
  <p>I'm trying to query menu list from database and return it as json format like below:</p>
  
  <pre><code> [{
      "name": "Account Settings",
      "icon": "fa fa-cog"
    }, {
      "name": "Support",
      "icon": "fa fa-wrench",
      "children": [{
        "name": "FAQ",
        "icon": "fa fa-question"
      }, {
        "name": "Contact",
        "icon": "fa fa-phone"
      }]
    }]
  </code></pre>
  
  <p>However, I don't know how can I insert the child into the parent section.</p>
  
  <p>My code as below:</p>
  
  <pre><code>$menu_list = MobMenu::all('name', 'icon', 'parent_id');
  
  foreach ($menu_list as $data) {
     $child = MobMenu::find($data-&gt;parent_id);
  }
  
  return json_encode($menu_list);
  </code></pre>
  
  <p>How can I create "children" and insert it into the parent section ?</p>