i have loop of check box items
@foreach ($product->productOptions as $productOption)
<input class="form-check-input" wire:model.live="productOptionPriceId" type="checkbox" value="{{ $productOption->id }}"> @endforeach
and my livewire component function
public function updated()
{
$basePrice = (float)$this->basePrice;
$selectedSizePrice = (float)$this->selectedSizePrice;
if ($this->productSizeId > 0) {
$model = ProductSize::select('price')->findOrFail($this->productSizeId);
$this->selectedSizePrice = number_format($model->price, 2);
}
if (count($this->productOptionPriceId) > 0) {
$option = ProductOption::select('price')->where('id', $this->productOptionPriceId)->get();
foreach ($option as $item) {
$this->selectedOptionPrice[] = number_format($item->price, 2);
}
$selectedOptionPrice = array_sum($this->selectedOptionPrice);
} else {
$selectedOptionPrice = 0;
}
$this->totalPrice = $basePrice + $selectedSizePrice + $selectedOptionPrice;
}
the broblem is when i checked input the value calculate and when uncheck and recheck add item an continue calculate not removing the unchecked value item this is the problem it not remove item from array and recalculate
please help