Last active
May 11, 2016 05:13
-
-
Save khoatran/5467624c07002d3274d0 to your computer and use it in GitHub Desktop.
[Laravel] MenuBuilder to build menu view-object from Laravel config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'admin_menu' => [ | |
[ | |
'name' => 'Content', | |
'label_key' => 'launchcms.menu.content', | |
'children' => [ | |
'content' => [ | |
'name' => 'Content', | |
'label_key' => 'launchcms.menu.content', | |
], | |
'structure' => [ | |
'name' => 'Structure', | |
'label_key' => 'launchcms.menu.content_type', | |
'url' => ['route_name' => 'cms_content_type_listing_page'] | |
] | |
] | |
] | |
] | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//I use this in method to load menuData by view composer approach. So, I put it in AppServiceProvider | |
public function boot() | |
{ | |
view()->composer('layout.main_menu', function ($view) { | |
$view->with('adminMenu', MenuBuilder::buildMenuViewObjectFromConfig('launchcms.admin_menu')); | |
}); | |
} | |
//When render the menu item, you just need to use main property: label, url on the view. That's it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment