update 2 inputs in live
i have 2 inputs amount and amout_persent. i want when i write amount automaticly fill the amount persent input with some logic.. just how i can make to autimaticly write something to next input?
18 Replies
Use
live()
on amount
field and ->afterStateUpdated(fn ($set) => $set('amount_persent')
yep thanks i found souliton
im using
but now problem is how i can take sum_amount π
im trying to find best way to how i can take sum_amont from another table speacial column
look, in this function i want to get amount_percent
It should be equal to whatever percentage of the sum_amount the amount is
i have sum_amount in another table and all table have their sum_amount
this amount_percent is another table ..
and im thinking how i can get actual sum_amount when im creating new table for another table like
when i dont know actual id to which row is this for
i have sum_amount in another table and all table have their sum_amountSorry, I can't follow. If you have
sum_amount
stored in the database in a different table, just load it via Eloquent/DB Facade?
when i dont know actual id to which row is this forWhy? The id should be
$record->id
?no im sorry i know that its to difficult becouse of me
okay let me show more detail
I have this table named pays
there is amount, amount_percent and also purchase_id
there is purchases table where i have sum_amount
in pays we have purchase_id and with that i can get sum_amount from purchase using purchase_id okay but
when im creating new pay for purchase
how i can get sum_amount from this purchase
becouse its possible to create many pays for one purchase
its more clear now ? π’
Why do you even store it and don't use
Payment::find('your_payment')->pays()->sum('amount'))
?btw in route i have something like this laso http://127.0.0.1:8000/admin/purchases/1
like last 1 is actual id of purchase
if its possible to use
there is many pays and everyone has thier own purchase_id so how it will take actual purchase sum amount?
how i can get sum_amount from this purchaseHow is this any different than any other purchase? I think your issue is just, that you need to recalculate the sum
all purchases has their own sum_amount
So, either always update the sum after every change (look at Laravel Observers, or Event) or always use
->sum()
on a database levelokay i will try to do with ur advice
thanks β€οΈ
I made it in just pay page but
purchase page down i have pays table
same as pay page
so when i click New pay in there and create new pay
how i can take this current purchase id?
becouse when i create new i have no idea which purchashe is it
Is this a relation manager? Then you can access
$livewire->ownerRecord
yep
this works now thanks for ur hint π