caffeinated / menus

:pushpin: Menu generator package for the Laravel framework
https://caffeinatedpackages.com
132 stars 59 forks source link

request: allow modules to add to menu #10

Closed illuminate3 closed 9 years ago

illuminate3 commented 9 years ago

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:

kaidesu commented 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
piperone commented 8 years ago

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?

kaidesu commented 8 years ago

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.