title: Dynamic menus from database in laravel using lavary/laravel-menu
body: <p>I have a laravel application with static menus. 
  Now I want to change this into dynamic menus from the database. 
  So far so good so I made a migration for a table called menu_items.</p>
  
  <p>Then I wrote a middleware with following handle method:</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
      \Menu::make('mainmenu', function ($menu) {
  
          $items = MenuItem::all();
  
          foreach ($items as $item) {
  
              if ($item-&gt;parent_id == null) {
  
                  $menu-&gt;add($item-&gt;title, $item-&gt;link)
                      -&gt;prepend('&lt;i class="'.$item-&gt;icon.'"&gt;&lt;/i&gt;');    
              }
              else {
                  // dd($menu);
                  $parent = $item-&gt;parent_id - 1;
                  $menu-&gt;find($parent)-&gt;add($item-&gt;title, $item-&gt;link);
              }
          }
  
      return $next($request);
  }
  </code></pre>
  
  <p>I changed to lavary/laravel-menu and try to get submenus added to the parent menu item dynamically. I do not understand why laravel always tells me at </p>
  
  <pre><code>$menu-&gt;find($parent)-&gt;add($item-&gt;title, $item-&gt;link);
  </code></pre>
  
  <p>Call to a member function add() on null $parent is not null if I print out with dd() If I do something like <code>$menu-&gt;last()-&gt;add($item-&gt;title, $item-&gt;link);</code> It works but thats not what I want...</p>