2026-01-27 11:31:02 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
|
|
|
|
class DocumentTemplateSectionItem extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'section_id',
|
|
|
|
|
'category',
|
|
|
|
|
'item',
|
|
|
|
|
'standard',
|
2026-02-02 16:29:45 +09:00
|
|
|
'tolerance',
|
2026-02-02 20:37:06 +09:00
|
|
|
'standard_criteria',
|
2026-01-27 11:31:02 +09:00
|
|
|
'method',
|
2026-02-02 16:29:45 +09:00
|
|
|
'measurement_type',
|
2026-02-02 20:37:06 +09:00
|
|
|
'frequency_n',
|
|
|
|
|
'frequency_c',
|
2026-01-27 11:31:02 +09:00
|
|
|
'frequency',
|
|
|
|
|
'regulation',
|
2026-02-04 08:38:00 +09:00
|
|
|
'field_values',
|
2026-01-27 11:31:02 +09:00
|
|
|
'sort_order',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
2026-02-04 08:38:00 +09:00
|
|
|
'tolerance' => 'array',
|
2026-02-02 20:37:06 +09:00
|
|
|
'standard_criteria' => 'array',
|
2026-02-04 08:38:00 +09:00
|
|
|
'field_values' => 'array',
|
2026-01-27 11:31:02 +09:00
|
|
|
'sort_order' => 'integer',
|
2026-02-02 20:37:06 +09:00
|
|
|
'frequency_n' => 'integer',
|
|
|
|
|
'frequency_c' => 'integer',
|
2026-01-27 11:31:02 +09:00
|
|
|
];
|
|
|
|
|
|
2026-02-04 08:38:00 +09:00
|
|
|
/**
|
|
|
|
|
* field_values 우선, 없으면 기존 컬럼 fallback
|
|
|
|
|
*/
|
|
|
|
|
public function getFieldValue(string $key): mixed
|
|
|
|
|
{
|
|
|
|
|
if (! empty($this->field_values) && array_key_exists($key, $this->field_values)) {
|
|
|
|
|
return $this->field_values[$key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->attributes[$key] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 11:31:02 +09:00
|
|
|
public function section(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(DocumentTemplateSection::class, 'section_id');
|
|
|
|
|
}
|
2026-02-04 08:38:00 +09:00
|
|
|
}
|