title: How to list select option with multi level categories in Laravel 5
body: <p>I have a question. Before asking this question I have searched a lot but I did not found any workable example, so I have put my question here. I have a concept of parent child relationship with in the same table for example, I have table category like this:</p>
  
  <pre><code>id int auto_increment primary
  name varchar
  type varchar
  parentid int 
  </code></pre>
  
  <p>Now I want to generate select box with multi level option like:</p>
  
  <pre><code>&lt;select class="category" name="category"&gt;
     &lt;option value="-1"&gt;Select Category&lt;/select&gt;
     &lt;optgroup value="0" label="Parent Tag"&gt;
        &lt;option value="1"&gt;Child Tag&lt;/option&gt;
        &lt;option value="2"&gt;Child Tag&lt;/option&gt;
     &lt;/optgroup&gt;
        &lt;optgroup value="3" label="Parent Tag"&gt;
        &lt;option value="4"&gt;Child Tag&lt;/option&gt;
        &lt;option value="5"&gt;Child Tag&lt;/option&gt;
     &lt;/optgroup&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I also want to generate Menus same as above.</p>
  
  <pre><code>&lt;ul&gt;
  &lt;li&gt;Menu 1&lt;/li&gt;
  &lt;li&gt;
     Menu 2
     &lt;ul class="dropdown"&gt;
       &lt;li&gt;Menu 1 of 2&lt;/li&gt;
       &lt;li&gt;Menu 2 of 2&lt;/li&gt;
       &lt;li&gt;Menu 3 of 2&lt;/li&gt;
     &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Menu 3&lt;/li&gt;
  &lt;li&gt;
  menu 4
     &lt;ul class="dropdown"&gt;
       &lt;li&gt;Menu 1 of 4&lt;/li&gt;
       &lt;li&gt;Menu 2 of 4&lt;/li&gt;
       &lt;li&gt;Menu 3 of 4&lt;/li&gt;
     &lt;/ul&gt;
  &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Please friends help to achieve this functionality in laravel 5. Depth for this is not limited and it can be 2, 3, 4; as many as the user wants to add.</p>
  
  <pre><code>Model
  class Category extends Model{
  ...
  public function parent()
      {
          return $this-&gt;belongsTo('App\Models\Category', 'parentid');
      }
  
      public function children()
      {
          return $this-&gt;hasMany('App\Models\Category', 'parentid');
      }
  }
  
  In Controller
  $categories = Category::with('children')-&gt;select('name', 'id','parentid')-&gt;where('configtype','=','Category')-&gt;get();
  return view('admin.category.index',['pageTitle' =&gt; 'Category', 'configlist' =&gt; $categories]);
  
  In view
  ?
  </code></pre>