'integer', 'changed_at' => 'datetime', 'before_snapshot' => 'array', 'after_snapshot' => 'array', ]; /** * 단가 관계 */ public function price(): BelongsTo { return $this->belongsTo(Price::class, 'price_id'); } /** * 변경자 관계 */ public function changedByUser(): BelongsTo { return $this->belongsTo(\App\Models\Members\User::class, 'changed_by'); } /** * 변경된 필드 목록 추출 */ public function getChangedFields(): array { if (! $this->before_snapshot) { return array_keys($this->after_snapshot ?? []); } $changed = []; foreach ($this->after_snapshot as $key => $newValue) { $oldValue = $this->before_snapshot[$key] ?? null; if ($oldValue !== $newValue) { $changed[] = $key; } } return $changed; } /** * 특정 필드의 이전/이후 값 */ public function getFieldChange(string $field): array { return [ 'before' => $this->before_snapshot[$field] ?? null, 'after' => $this->after_snapshot[$field] ?? null, ]; } }