Files
sam-manage/app/Models/Equipment/EquipmentInspectionDetail.php
김보곤 c84c8894be feat: [database] Equipment 하위 4개 모델 codebridge connection 추가
- EquipmentInspection, EquipmentInspectionDetail, EquipmentInspectionTemplate, EquipmentRepair
- equipments 테이블과 FK 참조 관계 → 동일 DB(codebridge)에서 관리
2026-03-09 20:57:49 +09:00

64 lines
1.5 KiB
PHP

<?php
namespace App\Models\Equipment;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EquipmentInspectionDetail extends Model
{
protected $connection = 'codebridge';
protected $fillable = [
'inspection_id',
'template_item_id',
'check_date',
'result',
'note',
];
protected $casts = [
'check_date' => 'date',
];
public function inspection(): BelongsTo
{
return $this->belongsTo(EquipmentInspection::class, 'inspection_id');
}
public function templateItem(): BelongsTo
{
return $this->belongsTo(EquipmentInspectionTemplate::class, 'template_item_id');
}
public function getResultSymbolAttribute(): string
{
return match ($this->result) {
'good' => '○',
'bad' => 'X',
'repaired' => '△',
default => '',
};
}
public function getResultColorAttribute(): string
{
return match ($this->result) {
'good' => 'text-green-600',
'bad' => 'text-red-600',
'repaired' => 'text-yellow-600',
default => 'text-gray-400',
};
}
public static function getNextResult(?string $current): ?string
{
return match ($current) {
null, '' => 'good',
'good' => 'bad',
'bad' => 'repaired',
'repaired' => null,
default => 'good',
};
}
}