-
Notifications
You must be signed in to change notification settings - Fork 2
Add Menu Classes to Menu #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,8 @@ function generate() | |
$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 | ||
$this->menu->add('Sub Menu', 'sub-menu:sub_menu_name); // Method 9 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot closing single-quote |
||
|
||
} | ||
``` | ||
|
@@ -131,6 +133,8 @@ function generate() | |
| 5 | The `$this->menu` instance | The route is associated with arguments, useful to create a quick route with parameters. | | ||
| 6 | A new `MenuItem` | The route is assigned using the fluent interface, which makes the code look cleaner. You can also add an array of route parameters as the second argument. | | ||
| 7 | The `$this->menu` instance | You can pass an array as the second argument to immediately issue all the variables to the menu item, when you don't want to use the fluent interface. | | ||
| 8 | The `$this->menu` instance | You can pass the name of another menu and the class will merge that menu with this menu. | | ||
| 9 | The `$this->menu` instance | You can pass the name of another menu and the class will pull in that menu as a sub menu. | | ||
|
||
|
||
|
||
|
@@ -285,4 +289,4 @@ This should achieve a menu looking like [the default bootstrap navbar](https://g | |
|
||
|
||
# Tips | ||
- The `__construct` of your menu class works with dependency injection. Simply type hint the stuff you need in the parameter list and we'll ask Laravel to inject the stuff you need. | ||
- The `__construct` of your menu class works with dependency injection. Simply type hint the stuff you need in the parameter list and we'll ask Laravel to inject the stuff you need. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,11 +93,33 @@ public function &add(string $title, $config = null) | |
|
||
return $this; | ||
} | ||
|
||
|
||
// Is it another Menu? | ||
if(starts_with($config, 'menu:') || starts_with($config, 'sub-menu:')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space after if |
||
$slug = $item['__slug__'] = snake_case($title); | ||
|
||
if(starts_with($config, 'menu:')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space after if |
||
$items =& $this->_items; | ||
$menu = app('menu')->get(str_replace_first('menu:', '', $config)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should either return $this (soft failure) or throw exception if menu doesn't exist. |
||
} else {// if(starts_with($config, 'sub-menu:')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the comment containing logical code |
||
$items =& $item->_items; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$menu = app('menu')->get(str_replace_first('sub-menu:', '', $config)); | ||
} | ||
|
||
$items = array_merge($items, $menu->_items); | ||
|
||
if(starts_with($config, 'sub-menu:')) { | ||
$this->_items[$slug] = &$item; | ||
} | ||
|
||
return $this; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad indentation. Make sure you use spaces (4) instead of tabs. |
||
|
||
// Else it's a plain url | ||
$this->_items[snake_case($title)] = &$item; | ||
$item->url = $config; | ||
|
||
return $this; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot closing single-quote