Conversation
Allow the user to add a menu as a sub item of a menu.
Add support for sub menu addition
Allow Menu to be merged with current menu or make a sub menu
TheDeadCode
left a comment
There was a problem hiding this comment.
You should most likely use an IDE like PHPStorm to prevent most style or linting issue highlighted. Regular editors tend to mess up a bit the spaces.
| $this->menu->add('Logout')->route('auth.logout'); // Method 6 | ||
| $this->menu->add('Some Other Link', ['url' => '/link']); // Method 7 | ||
| $this->menu->add('Sub Menu', 'menu:menu_name); // Method 8 | ||
| $this->menu->add('Sub Menu', 'sub-menu:sub_menu_name); // Method 9 |
There was a problem hiding this comment.
Forgot closing single-quote
| $this->menu->add('Edit Myself', 'route:users.edit|id:5'); // Method 5 | ||
| $this->menu->add('Logout')->route('auth.logout'); // Method 6 | ||
| $this->menu->add('Some Other Link', ['url' => '/link']); // Method 7 | ||
| $this->menu->add('Sub Menu', 'menu:menu_name); // Method 8 |
There was a problem hiding this comment.
Forgot closing single-quote
| } | ||
|
|
||
| return $this; | ||
| } |
There was a problem hiding this comment.
Bad indentation. Make sure you use spaces (4) instead of tabs.
| if(starts_with($config, 'menu:')) { | ||
| $items =& $this->_items; | ||
| $menu = app('menu')->get(str_replace_first('menu:', '', $config)); | ||
| } else {// if(starts_with($config, 'sub-menu:')) { |
There was a problem hiding this comment.
Remove the comment containing logical code
|
|
||
| if(starts_with($config, 'menu:')) { | ||
| $items =& $this->_items; | ||
| $menu = app('menu')->get(str_replace_first('menu:', '', $config)); |
There was a problem hiding this comment.
Should either return $this (soft failure) or throw exception if menu doesn't exist.
|
|
||
|
|
||
| // Is it another Menu? | ||
| if(starts_with($config, 'menu:') || starts_with($config, 'sub-menu:')) { |
| if(starts_with($config, 'menu:') || starts_with($config, 'sub-menu:')) { | ||
| $slug = $item['__slug__'] = snake_case($title); | ||
|
|
||
| if(starts_with($config, 'menu:')) { |
| $items =& $this->_items; | ||
| $menu = app('menu')->get(str_replace_first('menu:', '', $config)); | ||
| } else {// if(starts_with($config, 'sub-menu:')) { | ||
| $items =& $item->_items; |
There was a problem hiding this comment.
$item->_items is a protected item and it should stay that way. I'd suggest moving the functionality away from the add method and move it to a merge method under the trait CreatesMenuItems.
Allow user to add another menu to a menu, either as a sub-menu or merged into the current menu. This will be good for when there is various levels of permissions.