where('code', 'super_admin')->first(); if (! $role) { $this->command?->warn('未找到 roles.code=super_admin,已跳过。请先运行 DatabaseSeeder / AdminInitSeeder。'); return; } $opsRoot = Menu::query()->firstOrCreate( ['path' => '/operations', 'parent_id' => null], [ 'name' => 'Operations', 'title' => '运营管理', 'component' => null, 'icon' => 'Goods', 'sort' => 50, 'visible' => 1, 'keep_alive' => 0, 'permission_code' => null, 'status' => 1, ] ); $opsChildren = [ ['/courses', 'OperationsCourses', '课程管理', 'operations/courses/index', 10, 'Notebook'], ['/activities', 'OperationsActivities', '活动管理', 'operations/activities/index', 20, 'Calendar'], ['/news', 'OperationsNews', '资讯管理', 'operations/news/index', 30, 'Reading'], ]; $ids = [$opsRoot->id]; foreach ($opsChildren as $row) { $m = Menu::query()->firstOrCreate( ['path' => $row[0], 'parent_id' => $opsRoot->id], [ 'name' => $row[1], 'title' => $row[2], 'component' => $row[3], 'icon' => $row[5], 'sort' => $row[4], 'visible' => 1, 'keep_alive' => 0, 'permission_code' => null, 'status' => 1, ] ); $ids[] = $m->id; } $role->menus()->syncWithoutDetaching($ids); $this->command?->info('运营管理菜单已挂载到 super_admin(增量)。'); } }