'array', 'calculated_values' => 'array', 'unit_price' => 'decimal:2', 'quantity' => 'decimal:2', 'total_price' => 'decimal:2', 'bom_components' => 'array', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; /** * 견적 관계 */ public function estimate(): BelongsTo { return $this->belongsTo(Estimate::class); } /** * 순번별 정렬 */ public function scopeOrdered($query) { return $query->orderBy('sequence'); } /** * 총 금액 계산 */ public function calculateTotalPrice(): float { return $this->unit_price * $this->quantity; } /** * 저장 시 총 금액 자동 계산 */ protected static function boot() { parent::boot(); static::saving(function ($item) { $item->total_price = $item->calculateTotalPrice(); }); } }