laravel-menu
laravel-menu copied to clipboard
Nested groups do not work.
If I use example code:
Menu::make('MyNavBar', function($menu){
$menu->group(['prefix' => 'pages', 'data-info' => 'test'], function($m){
$m->add('About', 'about');
$m->group(['prefix' => 'about', 'data-role' => 'navigation'], function($a){
$a->add('Who we are', 'who-we-are?');
$a->add('What we do?', 'what-we-do');
$a->add('Our Goals', 'our-goals');
});
});
});
It gives me
<ul>
<li data-info="test"><a href="http://blabla.test/pages/about">About</a></li>
<li data-info="test" data-role="navigation"><a href="http://blabla.test/pages/about/who-we-are?">Who we are</a></li>
<li data-info="test" data-role="navigation"><a href="http://blabla.test/pages/about/what-we-do">What we do?</a></li>
<li data-info="test" data-role="navigation"><a href="http://blabla.test/pages/about/our-goals">Our Goals</a></li>
</ul>
Instead of
<ul>
...
<li data-info="test">
<a href="http://yourdomain.com/pages/about">About</a>
<ul>
<li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/who-we-are"></a></li>
<li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/what-we-do"></a></li>
<li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/our-goals"></a></li>
</ul>
</li>
</ul>
Seems to be a bug.
https://github.com/lavary/laravel-menu#nested-groups
A menu group merges its own attribute with its parent group then shares them between its wrapped items:
Groups are not nested menus. Groups do not create a new level of ULs.
What you want is a nested menu.
Try this.... https://github.com/lavary/laravel-menu#advanced-usage
Another example...
$about = $menu->add('About', ['url' => 'about', 'class' => 'navbar navbar-about dropdown']);
$about->attr(['class' => 'dropdown-toggle', 'data-toggle' => 'dropdown'])
->append('<b class="caret"></b>')
->prepend('<span class="glyphicon glyphicon-user"></span>');
$about->add('Our Attorneys', ['route' => 'attorneys'])
->active('attorneys/*/awesome');
The first $menu->add
returns the $about
element. From there you can add sub-items to that $about element with $about->add
Groups are not nested menus. Groups do not create a new level of ULs.
So... there is an error in documentation? Because in example it gives
<ul>
...
<li data-info="test">
<a href="http://yourdomain.com/pages/about">About</a>
<ul>
<li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/who-we-are"></a></li>
<li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/what-we-do"></a></li>
<li data-info="test" data-role="navigation"><a href="http://yourdomain.com/pages/about/our-goals"></a></li>
</ul>
</li>
</ul>
Yes, bug in either documentation or implementation.
Did a quick test and I would have thought the following would work. But, it doesn't. So yes, something is wrong. Thanks for identifying this.
\Menu::make('sMenu', function($menu) {
$menu->group(['prefix' => 'pages', 'data-info' => 'test'], function($m){
$about = $m->add('About', 'about');
$about->group(['prefix' => 'about', 'data-role' => 'navigation'], function($a){
$a->add('Who we are', 'who-we-are?');
$a->add('What we do?', 'what-we-do');
$a->add('Our Goals', 'our-goals');
});
});
});
https://github.com/lavary/laravel-menu/issues/115#issuecomment-203775319
Working version of the code