'boolean', ]; public function vendingMachine(): BelongsTo { return $this->belongsTo(VendingMachine::class); } public function products(): BelongsToMany { return $this->belongsToMany(Product::class, 'slot_product') ->withPivot('quantity', 'current_price') ->withTimestamps(); } public function currentProduct() { return $this->products()->wherePivot('quantity', '>', 0)->first(); } public function getTotalQuantityAttribute() { return $this->products()->sum('slot_product.quantity'); } }