English 中文(简体)
laravel-livewire如何使两个不同输入值之和从数据库表中提取并在另一个输入中得到结果
原标题:laravel livewire how to make sum of two deferent input valve fetched form database table and get result in another input

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}}" & keeping wire:model="Amount" i dont get value from foreach because i removed value="{{ $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 removed wire:model="Amount" & keeping value="{{ $prices->Amount}}" sum not works because value not reach to controller without wire: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();   
}
问题回答

您正在对一个Amount变量执行wire:model,但在价格的foreach内部执行。

因此,目前还不完全清楚你到底想安装什么。

您不应该使用value=“…”,因为Livewire通过wire:model自动从公共属性获取值。

此外,您可能应该在Result输入中使用wire:model

我不太清楚为什么会有这个循环,所以我会告诉你没有循环

<label>Amount</label>
<input wire:model="amount" name="Amount">

<label>Disscount</label>
<input type="text" wire:model="disscount" name="Disscount" >

<label>Result</label>
<input type="text" wire:model="result" name="Result" >

//组件

public $result;
public $amount;
public $disscount;

public function updatedAmount()
{
    $this->getTotalSum();
}

public function updatedDisscount()
{
    $this->getTotalSum();
}

public function getTotalSum()
{
    if ($this->amount && $this->disscount)
        $this->result = ($this->amount + $this->disscount)
}




相关问题
Table of calificacions in php and laravel

I created a table in order to show the name of the students, name of the subjects and the grade of the subject of the student I have the next code: this is the index part <form action="{{ ...

How to fix CORS for Capacitor/Quasar App in a Laravel API

I have an App built on top of Quasar and Capacitor, with an API built on top of Laravel. Everything works well on the dev environment until I build and install the app on my phone, then I keep getting ...

Laravel +Vuejs CORS issue

I am facing a dilemma wit the CORS issue. I have application that is configured as follow: API: https://abc.mydomain.com (laravel) front end: https://subdomain.mydomain.com(VueJS) Both applications ...

Laravel wrong redirecting to login page after login

In a multi tenancy with subdomain enviroment (http://zapburger.dex.local) when user fills login form with valid data and make login, laravel redirect to dashboard route (as expected) and then redirect ...

热门标签