public static addMenuItem ( string $category, integer $position, array $menu ) : void | ||
$category | string | 'user' or 'admin' |
$position | integer | Where to insert the given item, start from 0. |
$menu | array | e.g. [ 'title' => 'Title', # will be translated by translator 'link' => 'user/config', # route link 'icon' => 'fa-book' # font-awesome icon ] |
return | void |
public static function addMenuItem($category, $position, array $menu)
{
$class = $category == "user" ? ConfigureUserMenu::class : ConfigureAdminMenu::class;
Event::listen($class, function ($event) use($menu, $position, $category) {
$new = [];
$offset = 0;
foreach ($event->menu[$category] as $item) {
// push new menu items at the given position
if ($offset == $position) {
$new[] = $menu;
}
$new[] = $item;
$offset++;
}
$event->menu[$category] = $new;
});
}