PHP code example of enimiste / knp-menu-laravel

1. Go to this page and download the library: Download enimiste/knp-menu-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

enimiste / knp-menu-laravel example snippets


Dowilcox\KnpMenu\MenuServiceProvider::class,

'Menu' => Dowilcox\KnpMenu\Facades\Menu::class,

$menu_builder = app('knp_menu.menu');

$menu = Menu::create('main-menu', ['childrenAttributes' => ['class' => 'nav']]);

/*
* This is the list of possible options for a menu item :
*
*     'uri' => null,
*     'label' => null,
*     'attributes' => array(),
*     'linkAttributes' => array(),
*     'childrenAttributes' => array(),
*     'labelAttributes' => array(),
*     'extras' => array(),
*     'current' => null,
*     'display' => true,
*     'displayChildren' => true,
*/

$menu->addChild('Home', [
'uri' => url('/'),
'attributes' => [
    'class'=>'your_css_class',
 ],
 'extras' => [
    'routes' => [
        ['route' => 'route_name_1'],
        ['route' => 'route_name_2'],
    ]
 ]
]);
$menu->addChild('Users', ['uri' => route('admin.users.index')]);
$menu->addChild('Roles', ['uri' => route('admin.roles.index')]);
$menu->addChild('Menu', ['uri' => url('menu')]);

echo Menu::render($menu);
//Or
echo Menu::render($menu, $custom_render_options);//$custom_render_options is an array
bash
php artisan vendor:publish --tag=knp_menu