Easy way to build navigation menus
$menu = new Menu('main-menu');
$menu->item('Home')->to('/');
$menu->item('Inbox')->to('inbox')->badge(5);
$menu->item('Reports')
->subMenu( function ( Menu $menu )
{
$menu->item('Summary')->to('/reports/summary');
$menu->item('Detailed')->to('/reports/detailed');
} );
$json = ( new \Roboc\Menu\Renderer\JsonRenderer )->render( $menu );
Output:
[
{
"title": "Home",
"link": "\/"
},
{
"title": "Inbox",
"link": "inbox",
"badge": {
"value": 5,
"attributes": []
}
},
{
"title": "Reports",
"children": [
{
"title": "Summary",
"link": "\/reports\/summary"
},
{
"title": "Detailed",
"link": "\/reports\/detailed"
}
]
}
]
$html = ( new \Roboc\Menu\Renderer\HtmlRenderer )->render( $menu );
Output:
<ul id="main-menu">
<li><a href="/">Home</a></li>
<li><a href="/inbox">Inbox <span class="badge">5</span></a></li>
<li>Reports
<ul>
<li><a href="/reports/summary">Summary</a></li>
<li><a href="/reports/detailed">Detailed</a></li>
</ul>
</li>
</ul>
You can create your own menu renderer or build menu output direclty in your code