'boolean', 'sort_order' => 'integer', ]; /** * 부모 카테고리 */ public function parent(): BelongsTo { return $this->belongsTo(self::class, 'parent_id'); } /** * 자식 카테고리 */ public function children(): HasMany { return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order'); } /** * 재귀적으로 자식 카테고리 로드 */ public function childrenRecursive(): HasMany { return $this->children()->with('childrenRecursive'); } /** * 코드 그룹 스코프 */ public function scopeGroup($query, string $group) { return $query->where('code_group', $group); } /** * 루트 카테고리만 조회 */ public function scopeRoot($query) { return $query->whereNull('parent_id'); } /** * 활성 카테고리만 조회 */ public function scopeActive($query) { return $query->where('is_active', true); } }