F
Filament5mo ago
HGalih

get new repeater item only filament when editing

I want to decrease user balance everytime they order. This is what I did
protected function mutateFormDataBeforeCreate(array $data): array
{
$user = Auth::user();
$data['user_id'] = $user->id;
if(auth()->user()->balance < $data['total_price'])
throw new \Exception('Insufficient balance');

foreach ($this->data['paket_bot'] as &$value) {
$package = \App\Models\BotPackage::find($value['bot_package_id']);
$value['expired_at'] = now()->addDays($package->day_count);
if($value['quantity'] < 1) $value['quantity'] = 1;
$value['price'] = $package->discounted * $value['quantity'];
}

$user->decreaseOrIncreaseBalance(-$data['total_price']);
return $data;
}
protected function mutateFormDataBeforeCreate(array $data): array
{
$user = Auth::user();
$data['user_id'] = $user->id;
if(auth()->user()->balance < $data['total_price'])
throw new \Exception('Insufficient balance');

foreach ($this->data['paket_bot'] as &$value) {
$package = \App\Models\BotPackage::find($value['bot_package_id']);
$value['expired_at'] = now()->addDays($package->day_count);
if($value['quantity'] < 1) $value['quantity'] = 1;
$value['price'] = $package->discounted * $value['quantity'];
}

$user->decreaseOrIncreaseBalance(-$data['total_price']);
return $data;
}
'paket_bot' is a repeater that hold product datas. The catch is they can also update it (add more product but not delete previous product). And if they do add another product, I need to decrease the balance again. How do I avoid decreasing the user balance for the previous ordered item? (because repeater hold both old and new product data)
0 Replies
No replies yetBe the first to reply to this messageJoin