Hello im new to laravel livewire now im trying to sum of two values and result get in another input filed. but laravel i did this using jQuery now im trying livewire instead of jQuery.
现在我通过foreach循环从数据库表中获得第一个输入值,第二个输入值我手动插入,第三个输入值得到结果。
问题1
but im facing problem in 1st input if i use foreach with
wire:model="Amount"
&value="{{ $prices->Amount}}"
at same time in input i get empty.
@foreach ($price $prices)
<label>Amount</label>
<input wire:model="Amount" name="Amount" value="{{ $prices->Amount}}">
@endforeach
<label>Disscount</label>
<input type="text" wire:model="Disscount" name="Disscount" >
<label>Result</label>
<input type="text" value="{{ $result }}" name="Disscount" >
问题2
if i removed code
value="{{ $prices->Amount}}"
& keepingwire:model="Amount"
i dont get value from foreach because i removedvalue="{{ $prices->Amount}}"
this time i entered manually insert value in input it works i get result, but i need to sum value with foreach value. if i removedwire:model="Amount"
& keepingvalue="{{ $prices->Amount}}"
sum not works because value not reach to controller withoutwire:mode
.
@foreach ($price $prices)
<label>Amount</label>
<input wire:model="Amount" name="Amount" value="{{ $prices->Amount}}">
@endforeach
<label>Disscount</label>
<input type="text" wire:model="Disscount" name="Disscount" >
<label>Result</label>
<input type="text" value="{{ $result }}" name="Disscount" >
我的控制器
public $result;
public $Amount;
public $Disscount;
public function updated() //used for sum
{
$this->result = $this->Amount - $this->Disscount;
}
public function mount()
{
$this->price = Pricing::all();
}