To create a menu, you can use the ‘addMenuItem‘ helper in the MenuItemsTableSeeder run method.
The ‘addMenuItem‘ helper takes three parameters. The first one is for the panel, the second one is for the menu name, and the third one is for an array.
- For the first parameter, you can provide the panel name like ‘admin’, ‘vendor’, or ‘customer’. You can also use the menu_id like ‘1’. Example:
addMenuItem('admin', 'second-parameter', 'third-parameter')
addMenuItem('vendor', 'second-parameter', 'third-parameter')
addMenuItem('1', 'second-parameter', 'third-parameter')
- The second parameter will be the menu name. Example:
addMenuItem('admin', 'Subscription', 'third-parameter')
- The third parameter is an optional array where you can set values like parent, link, params, sort, etc.
- If you don’t provide ‘parent’ in the third parameter array, then the menu will be a parent menu, and it will return an id.
- You can set the parent value as ‘parentId’ or ‘parentName’.
- If the menu already exists, the menu will be updated with the third parameter array.
Example:
$parentId = addMenuItem('admin', 'Google Analytics', [
'icon' => 'fas fa-chart-line',
'sort' => 27,
]);
addMenuItem('admin', 'Dashboard', [
'parent' => $parentId,
'link' => 'analytics-dashboard',
'params' => '{"permission":"..."}',
'sort' => 28
]);
addMenuItem('1', 'Settings', [
'parent' => 'Google Analytics',
'link' => 'analytics-settings',
'params' => '{"permission":"..."}',
'sort' => 31,
]);