caffeinated / menus

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

Add new item from controller #27

Closed ghost closed 9 years ago

ghost commented 9 years ago

Good evening,

how can I add a new menu item to an existing menu instance within the controller ?

Sorry for my bad english. I'm German.

Greetings,

kaidesu commented 9 years ago

Sorry, looks like I forgot to write the documentation on this! It's simple though:

Creating our initial menu:

Menu::make('example', function($menu) {
    $menu->add('Link 1', '/link-1');
    $menu->add('Link 2', '/link-2);
});

Somewhere else (in a controller, for instance):

$menu = Menu::get('example');

$menu->add('Link 3', '/link-3');
$menu->add('Link 4', '/link-4');
ghost commented 9 years ago

And from an service provider? It's possible ?

ghost commented 9 years ago

Background:

I've use the Skylabs Module Plugin and each modules should have the possibilty to register a menu point. The menu service provider is located in Core Module.

ghost commented 9 years ago

Current value is "null". Within the Controller all okay.

kaidesu commented 9 years ago

Yes, that is certainly possible (and the best location, imho)! Just be sure that your menu is created before trying to get() it and add items to it.

ghost commented 9 years ago

Okay, it’s functional.

How can I use sub menu points ?

Von: Shea Lewis [mailto:notifications@github.com] Gesendet: Donnerstag, 30. April 2015 01:33 An: caffeinated/menus Cc: virtualstep Betreff: Re: [menus] Add new item from controller (#27)

Yes, that is certainly possible (and the best location, imho)! Just be sure that your menu is created before trying to get() it and add items to it.

— Reply to this email directly or view it on GitHub https://github.com/caffeinated/menus/issues/27#issuecomment-97614034 . https://github.com/notifications/beacon/AKNhIOC_3BtR93rIHEnqsHes8tEvF2Ydks5oEWGjgaJpZM4EL4Fq.gif

ghost commented 9 years ago

I find It out.

Add this please to your doc.

$menu->add('Blog', 'blog'); $menu->blog->add('Blog 2', 'blog');

kaidesu commented 9 years ago

Documentation on adding menu items can be found here now: https://github.com/caffeinated/menus/wiki/Basics-of-Menu-Items