fix:AI 토큰 사용량 시더 - AI 관리 독립 그룹으로 변경

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-07 10:36:19 +09:00
parent 55f604ce6f
commit 1d12a75ac7

View File

@@ -11,48 +11,61 @@ public function run(): void
{
$tenantId = 1;
// 시스템 관리 부모 메뉴 찾기
$parentMenu = Menu::where('tenant_id', $tenantId)
->where('name', '시스템 관리')
// AI 관리 부모 그룹 찾기 또는 생성
$parentMenu = Menu::withoutGlobalScopes()
->where('tenant_id', $tenantId)
->where('name', 'AI 관리')
->whereNull('parent_id')
->whereNull('deleted_at')
->first();
if (! $parentMenu) {
$this->command->error('시스템 관리 메뉴를 찾을 수 없습니다.');
return;
$parentMenu = Menu::withoutGlobalScopes()->create([
'tenant_id' => $tenantId,
'parent_id' => null,
'name' => 'AI 관리',
'url' => null,
'icon' => 'brain-circuit',
'sort_order' => 12,
'is_active' => true,
]);
$this->command->info("AI 관리 부모 그룹 생성 완료 (id: {$parentMenu->id})");
}
// 이미 존재하는지 확인
$existingMenu = Menu::where('tenant_id', $tenantId)
// AI 토큰 사용량 메뉴 존재 확인
$existingMenu = Menu::withoutGlobalScopes()
->where('tenant_id', $tenantId)
->where('name', 'AI 토큰 사용량')
->where('parent_id', $parentMenu->id)
->whereNull('deleted_at')
->first();
if ($existingMenu) {
$this->command->info('AI 토큰 사용량 메뉴가 이미 존재합니다.');
return;
} else {
$maxSort = Menu::withoutGlobalScopes()
->where('parent_id', $parentMenu->id)
->whereNull('deleted_at')
->max('sort_order') ?? 0;
Menu::withoutGlobalScopes()->create([
'tenant_id' => $tenantId,
'parent_id' => $parentMenu->id,
'name' => 'AI 토큰 사용량',
'url' => '/system/ai-token-usage',
'icon' => 'brain-circuit',
'sort_order' => $maxSort + 1,
'is_active' => true,
]);
$this->command->info('AI 토큰 사용량 메뉴 생성 완료');
}
// 현재 자식 메뉴 최대 sort_order 확인
$maxSort = Menu::where('parent_id', $parentMenu->id)
->max('sort_order') ?? 0;
// 메뉴 생성
$menu = Menu::create([
'tenant_id' => $tenantId,
'parent_id' => $parentMenu->id,
'name' => 'AI 토큰 사용량',
'url' => '/system/ai-token-usage',
'icon' => 'brain-circuit',
'sort_order' => $maxSort + 1,
'is_active' => true,
]);
$this->command->info("메뉴 생성 완료: {$menu->name} (sort_order: {$menu->sort_order})");
// 하위 메뉴 목록 출력
// 결과 출력
$this->command->info('');
$this->command->info('=== 시스템 관리 하위 메뉴 ===');
$children = Menu::where('parent_id', $parentMenu->id)
$this->command->info('=== AI 관리 하위 메뉴 ===');
$children = Menu::withoutGlobalScopes()
->where('parent_id', $parentMenu->id)
->whereNull('deleted_at')
->orderBy('sort_order')
->get(['name', 'url', 'sort_order']);