'decimal:2', 'buy_price' => 'decimal:2', 'total' => 'decimal:2', 'received' => 'boolean', ]; public function purchase(): BelongsTo { return $this->belongsTo(Purchase::class); } public function part(): BelongsTo { return $this->belongsTo(Part::class); } protected static function booted(): void { static::saving(function (self $row) { $row->total = round((float) $row->qty * (float) $row->buy_price, 2); }); static::saved(fn (self $row) => $row->purchase?->recalcTotal()); static::deleted(fn (self $row) => $row->purchase?->recalcTotal()); } }