From 1653bb5d2e81757edd87d1973593ea33fa7cfb1f Mon Sep 17 00:00:00 2001 From: Abbas Arif <43321373+buzzclue@users.noreply.github.com> Date: Mon, 15 Jan 2024 04:30:55 +0500 Subject: [PATCH] consumeNotQuotaFeature keeps adding new consumptions Fixed not quota feature consumptions. --- src/Models/Concerns/HasSubscriptions.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Models/Concerns/HasSubscriptions.php b/src/Models/Concerns/HasSubscriptions.php index 14b3fe1..b2a53e1 100644 --- a/src/Models/Concerns/HasSubscriptions.php +++ b/src/Models/Concerns/HasSubscriptions.php @@ -293,13 +293,12 @@ protected function consumeNotQuotaFeature(Feature $feature, ?float $consumption : null; $featureConsumption = $this->featureConsumptions() - ->make([ - 'consumption' => $consumption, - 'expired_at' => $consumptionExpiration, - ]) - ->feature() - ->associate($feature); + ->whereFeatureId($feature->id) + ->firstOrNew(); + $featureConsumption->feature()->associate($feature); + $featureConsumption->consumption += $consumption; + $featureConsumption->expired_at = $consumptionExpiration; $featureConsumption->save(); return $featureConsumption;