dizatech/module-menu
Composer 安装命令:
composer require dizatech/module-menu
包简介
This package provides menu generator for modules in laravel apps.
README 文档
README
This package has a menu manager and menu generator for laravel modules.
Installation
Using Composer :
composer require dizatech/module-menu
packagist : https://packagist.org/packages/dizatech/module-menu
Admin Panel Usage
- publish blade files :
php artisan vendor:publish --tag=module-menu
** Please note if you already published the vendor, for updates you can run the following command :
php artisan vendor:publish --tag=module-menu --force
- run the following command :
php artisan migrate
- Add the following code to module service provider , at the end of boot() function :
\ModuleMenu::init('ExampleModule');
Please note that ExampleModule is your module name
- Add the following tags in your sidebar layout
(the module menus will be rendered by
modulestype and the menu manager will be rendered bymanagertype) :
<x-module-menu type="modules"></x-module-menu>
<x-module-menu type="manager"></x-module-menu>
or shorten tags :
<x-module-menu type="modules" />
<x-module-menu type="manager" />
Please note that the default type of x-module-menu tag is manager
Front-end Usage
to load desktop menus you must use this tag :
<x-front-menu menuGroup="desktop-navbar-menu"></x-front-menu>
to load mobile menus you must use this tag :
<x-front-menu menuGroup="mobile-navbar-menu"></x-front-menu>
Create Menus
Using UI (Menu Manager)
-
from
menu/createin your panel, you can create new menu -
manage created menus in the following url :
http://example.com/example-panel/menu
Please note that created menus are only available in module_menus table (in database),
if you want to have migratable menus, use the Laravel Seeder
Using Laravel Seeder
The standard structure for packages or core (4 seeder needed)
- for packages you can use pacman (package-manager) to create seeders simply.
Download and install pacman : https://packagist.org/packages/dizatech/pacman
MenuSeeder
Create menu items
-
create
<package_name>MenuSeederusingphp artisan pacman:seeder <package_name>MenuSeeder <package_name>command -
in
run()method add each menu in separateifconditions like the following codes:
** parent menu (first parent menu name must be equal to package name)
if (DB::table('module_menus')->where('name','<menu_name>')->count() == 0){ // for first parent you must use package_name for menu_name
$parentID = DB::table('menu_menus')->insertGetId([ // set parent id of menu in $parentID variable
'name' => '<menu_name>', // for first parent you must use package_name for menu_name
'title' => '<package_first_parent_name>', // e.g. فرم ها
'icon' => '<menu_icon>', // e.g. fa fa-wpforms
'route' => '<menu_route>', // e.g. form.index
'parent_id' => '0', // 0 for parent
'creator_id' => '1', // creator user_id
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString(),
'deleted_at' => null,
]);
}
** child menu
if (DB::table('module_menus')->where('name','<menu_name>')->count() == 0){
DB::table('module_menus')->insert([
'name' => '<menu_name>', // menu name, e.g. site_forms
'title' => '<child_name>', // menu title, e.g. ایجاد فرم
'icon' => '<menu_icon>', // child menu icon, e.g. fa fa-circle-o
'route' => '<menu_route>', // menu route, e.g. form.index
'parent_id' => $parentID, // menu parent id, can be dynamic
'creator_id' => '1', // creator user_id
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString(),
'deleted_at' => null,
]);
}
PermissionsSeeder
Create permission for each menu item
-
create
<package_name>PermissionsSeederusingphp artisan pacman:seeder <package_name>PermissionsSeeder <package_name>command -
in
run()method add the permissions in separateifconditions like the following code:
if (DB::table('permissions')->where('name','<permission_name>')->count() == 0){ // e.g. forms_access
DB::table('permissions')->insert([
'name' => '<permission_name>', // e.g. forms_access
'display_name' => '<permission_display_name>', // e.g. دسترسی فرم ها
'description' => '<permission_description>', // e.g. امکان دسترسی به فرم ها
'created_at' => now()->toDateTimeString(),
'updated_at' => now()->toDateTimeString()
]);
}
MenuPermissionsSeeder
Connect each menu to specific permission
-
create
<package_name>MenuPermissionsSeederusingphp artisan pacman:seeder <package_name>MenuPermissionsSeeder <package_name>command -
in
run()method add the following codes (first find menus, then attach theme permissions):
$parentMenu = ModuleMenu::where('name', '<parent_menu_name>')->first();
$childMenu = ModuleMenu::where('name', '<child_menu_name>')->first();
$parentMenu->permissions()->sync(Permission::where('name', '<permission_name>')->pluck('id'));
$childMenu->permissions()->sync(Permission::where('name', '<permission_name>')->pluck('id'));
RolePermissionsSeeder
Connect each permission to specific role
-
create
<package_name>RolePermissionsSeederusingphp artisan pacman:seeder <package_name>RolePermissionsSeeder <package_name>command -
in
run()method add the following codes (first find role, then attach permissions to it):
$<role_name> = Role::where('name', '<role_name>')->first(); // main role
$permissions = DB::table('permissions')->whereIn('name', [
'<permission_name_one>',
'<permission_name_two>',
...
])->get()->pluck('id');
$<role_name>->permissions()->sync($permissions, false);
add new seeders in laravel core
- add new seeders in
/database/seeders/DatabaseSeeder.php:
public function run()
{
$this->call([
ProvinceSeeder::class,
UserSeeder::class,
// new classes goes here
]);
}
Last step for laravel seeder
- run artisan seed :
php artisan db:seed
- clear all caches :
php artisan cache:clear
php artisan view:clear
php artisan route:clear
ChangeLog
dizatech/module-menu 适用场景与选型建议
dizatech/module-menu 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 256 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dizatech/module-menu 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dizatech/module-menu 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 256
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-19