where('name', '영업관리') ->whereNull('parent_id') ->whereNull('deleted_at') ->get(); if ($salesMenus->isEmpty()) { $this->command->error('영업관리 메뉴를 찾을 수 없습니다.'); return; } foreach ($salesMenus as $salesMenu) { $tenantId = $salesMenu->tenant_id; $label = $tenantId ? "tenant_id={$tenantId}" : 'global(tenant_id=null)'; // 이미 존재하는지 확인 $exists = Menu::withoutGlobalScopes() ->where('parent_id', $salesMenu->id) ->where('name', '인터뷰 시나리오') ->whereNull('deleted_at') ->exists(); if ($exists) { $this->command->info("[{$label}] 인터뷰 시나리오 메뉴가 이미 존재합니다."); continue; } // 마지막 sort_order 확인 $maxSort = Menu::withoutGlobalScopes() ->where('parent_id', $salesMenu->id) ->whereNull('deleted_at') ->max('sort_order') ?? 0; Menu::withoutGlobalScopes()->create([ 'tenant_id' => $tenantId, 'parent_id' => $salesMenu->id, 'name' => '인터뷰 시나리오', 'url' => '/sales/interviews', 'icon' => 'clipboard-check', 'sort_order' => $maxSort + 1, 'is_active' => true, ]); $this->command->info("[{$label}] 인터뷰 시나리오 메뉴 생성 완료."); } } }