hasMany(EggCollectionItem::class); } public function warehouse(): BelongsTo { return $this->belongsTo(Warehouse::class); } public function syncTotals() { $this->total_eggs = $this->items()->where('is_broken', false)->sum('quantity'); $this->total_broken_eggs = $this->items()->where('is_broken', true)->sum('quantity'); $this->saveQuietly(); } protected function casts(): array { return [ 'production_date' => 'datetime', 'total_eggs' => 'decimal:2', 'total_broken_eggs' => 'decimal:2', ]; } }