I have input with dinamic field so i can add more colomn and remove it . in this input i have colomn total_price , on price i need price * qty . but i dont know how do this on multiple input . i just can do this on single input . my form and livewire like this :
-
form
<form> <button wire:click.prevent="add({{$i}})"> Add </button> <input type="hidden" wire:model="newid.0"> <input wire:model="nama_barang.0" type="text" /> <input wire:model="qtt.0" type="text" /> <input wire:model="price.0" type="text" /> <input wire:model="qty.0" type="text" /> <input wire:model="total_price" type="text" /> // here the problem @foreach($inputs as $key => $value) <input wire:model="nama_barang.{{ $value }}" type="text" /> <input wire:model="qtt.{{ $value }}" type="text" /> <input wire:model="price.{{ $value }}" type="text" /> <input wire:model="qty.{{ $value }}" type="text" /> <input wire:model="total_price" type="text" /> // on here i get the problem @endforeach <button wire:click.prevent="store()">Submit</button> </form>
and this is my livewire
public $belanja_id, $nama_barang, $qtt,$newid;
public $updateMode = false;
public $inputs = [];
public $i = 1;
public $total_price ;
public $price= [] ;
public $qty = [];
public function add($i)
{
$i = $i + 1;
$this->i = $i;
array_push($this->inputs ,$i);
}
public function mount($id)
{
$belanja = $this->belanja = Belanja::findOrFail($id);
$this->newid = $belanja->id;
$this->k_uraian = $belanja->uraian;
}
public function remove($i)
{
unset($this->inputs[$i]);
}
public function render()
{
$this->total_price =array_sum($this->price) * array_sum($this->qty) ; // i try with this but only get 1 rows , can someone help ?
return view('livewire.input-belanja-lw');
}
and you can see my form on this picture (better u see this picture so u can know my problem) , i cant add sum total_price . so can someone help about this ?
my references is from this site site