diff --git a/app/Models/Products/CommonCode.php b/app/Models/Products/CommonCode.php index 59c0689..ac509f7 100644 --- a/app/Models/Products/CommonCode.php +++ b/app/Models/Products/CommonCode.php @@ -8,12 +8,35 @@ class CommonCode extends Model { use SoftDeletes; - protected $fillable = ['tenant_id','code_group','code','name','parent_id','description','is_active','sort_order']; - public function parent() { + protected $table = 'common_codes'; + + protected $fillable = [ + 'tenant_id', + 'code_group', + 'code', + 'name', + 'parent_id', + 'attributes', + 'description', + 'is_active', + 'sort_order' + ]; + + protected $casts = [ + 'attributes' => 'array', + 'is_active' => 'boolean', + ]; + + // 관계: 상위 코드 + public function parent() + { return $this->belongsTo(self::class, 'parent_id'); } - public function children() { + + // 관계: 하위 코드들 + public function children() + { return $this->hasMany(self::class, 'parent_id'); } } diff --git a/database/migrations/2025_07_23_160852_create_common_codes_table.php b/database/migrations/2025_07_23_160852_create_common_codes_table.php new file mode 100644 index 0000000..7758278 --- /dev/null +++ b/database/migrations/2025_07_23_160852_create_common_codes_table.php @@ -0,0 +1,32 @@ +json('attributes')->nullable()->comment('동적 속성')->after('parent_id'); + } + // 2. is_active 타입 및 코멘트 변경 + $table->tinyInteger('is_active')->default(1)->comment('사용여부')->change(); + }); + + // 3. 테이블 코멘트 + DB::statement("ALTER TABLE `common_codes` COMMENT = '공통코드 트리';"); + } + + public function down(): void + { + Schema::table('common_codes', function (Blueprint $table) { + if (Schema::hasColumn('common_codes', 'attributes')) { + $table->dropColumn('attributes'); + } + }); + } +};