'integer', 'column_id' => 'integer', 'row_index' => 'integer', ]; protected $attributes = [ 'row_index' => 0, ]; // ========================================================================= // Relationships // ========================================================================= /** * 문서 */ public function document(): BelongsTo { return $this->belongsTo(Document::class); } // ========================================================================= // Scopes // ========================================================================= /** * 특정 섹션의 데이터 */ public function scopeForSection($query, int $sectionId) { return $query->where('section_id', $sectionId); } /** * 특정 필드 키의 데이터 */ public function scopeForField($query, string $fieldKey) { return $query->where('field_key', $fieldKey); } /** * 특정 행의 데이터 */ public function scopeForRow($query, int $rowIndex) { return $query->where('row_index', $rowIndex); } // ========================================================================= // Helper Methods // ========================================================================= /** * 값을 특정 타입으로 캐스팅 */ public function getTypedValue(string $type = 'string'): mixed { return match ($type) { 'integer', 'int' => (int) $this->field_value, 'float', 'double' => (float) $this->field_value, 'boolean', 'bool' => filter_var($this->field_value, FILTER_VALIDATE_BOOLEAN), 'array', 'json' => json_decode($this->field_value, true), default => $this->field_value, }; } }