AdminMenuSeeder.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Module\Friend\Databases\Seeders;
  3. use Dcat\Admin\Models\Menu;
  4. use Illuminate\Database\Seeder;
  5. use Illuminate\Support\Facades\DB;
  6. /**
  7. * 后台菜单填充器
  8. */
  9. class AdminMenuSeeder extends Seeder
  10. {
  11. /**
  12. * 运行填充器
  13. *
  14. * @return void
  15. */
  16. public function run()
  17. {
  18. // 检查是否已存在好友模块菜单
  19. $existingMenu = Menu::where('title', '好友管理')->first();
  20. if ($existingMenu) {
  21. return;
  22. }
  23. // 获取父级菜单ID
  24. $parentId = Menu::where('title', '系统管理')->value('id') ?? 0;
  25. // 创建好友模块父级菜单
  26. $friendMenuId = DB::table('admin_menu')->insertGetId([
  27. 'parent_id' => $parentId,
  28. 'order' => 10,
  29. 'title' => '好友管理',
  30. 'icon' => 'fa-users',
  31. 'uri' => null,
  32. 'created_at' => now(),
  33. 'updated_at' => now(),
  34. ]);
  35. // 创建好友关系管理菜单
  36. DB::table('admin_menu')->insert([
  37. 'parent_id' => $friendMenuId,
  38. 'order' => 1,
  39. 'title' => '好友关系管理',
  40. 'icon' => 'fa-link',
  41. 'uri' => 'friend-relations',
  42. 'created_at' => now(),
  43. 'updated_at' => now(),
  44. ]);
  45. // 创建好友申请管理菜单
  46. DB::table('admin_menu')->insert([
  47. 'parent_id' => $friendMenuId,
  48. 'order' => 2,
  49. 'title' => '好友申请管理',
  50. 'icon' => 'fa-paper-plane',
  51. 'uri' => 'friend-requests',
  52. 'created_at' => now(),
  53. 'updated_at' => now(),
  54. ]);
  55. }
  56. }