Closed illuminate3 closed 9 years ago
Nah, just a lack of documentation! You can get and add on to any menu that's been previously created:
Menu::make('example', function($menu) {
$menu->add('Home', '/');
$menu->add('About', 'about');
});
// Elsewhere in your code
$menu = Menu::get('example');
$menu->add('Blog', 'blog');
$menu->blog->add('Some Category', 'category/some-category'); // Menu items can be nested as well
I have a related question. What if you need to filter() the menu after all menu-items (from several modules) have been added. Where would you put that code?
I'm not actually using your module-package, rather I'm splitting my app into composer-packages. I'm adding to the menu in each of the packages service providers. The only place I can think of putting the menu-filtering would be a middleware (since they are executed after service providers).
What do you think?
Could try that - I call the filter method every time I make changes to the menu (i.e. for each module that modifies a menu, call the filter method at the end).
Though I haven't done any benchmarks on it, so I don't know how it affects performance. Ideally it'd be good to call it just once after a menu has been built as you said.
Played around with this about but haven't gotten the ability to allow multiple modules to add to the menu. It does work for a single module but it's first come first served.
Or ... is this a typical me mistake :wink: