Files
sam-manage/database/seeders/AiTokenUsageMenuSeeder.php
2026-02-07 10:36:19 +09:00

77 lines
2.5 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\Commons\Menu;
use Illuminate\Database\Seeder;
class AiTokenUsageMenuSeeder extends Seeder
{
public function run(): void
{
$tenantId = 1;
// AI 관리 부모 그룹 찾기 또는 생성
$parentMenu = Menu::withoutGlobalScopes()
->where('tenant_id', $tenantId)
->where('name', 'AI 관리')
->whereNull('parent_id')
->whereNull('deleted_at')
->first();
if (! $parentMenu) {
$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})");
}
// 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 토큰 사용량 메뉴가 이미 존재합니다.');
} 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 토큰 사용량 메뉴 생성 완료');
}
// 결과 출력
$this->command->info('');
$this->command->info('=== AI 관리 하위 메뉴 ===');
$children = Menu::withoutGlobalScopes()
->where('parent_id', $parentMenu->id)
->whereNull('deleted_at')
->orderBy('sort_order')
->get(['name', 'url', 'sort_order']);
foreach ($children as $child) {
$this->command->info("{$child->sort_order}. {$child->name} ({$child->url})");
}
}
}