lalalala lalalala - 1 year ago 87
PHP Question

Sum value from db in laravel

I'm trying to Sum the value from database to other value. But It keeps only insert the value not the sum of the value. Any ideas?

foreach ($isisjkirims as $key => $isisjkirim)
IsiSJKirim::where('IsiSJKir', $isisjkir[$key])
->update(['QSisaKemInsert' => 'QSisaKemInsert' + $qtertanda[$key]]);
} ^
i think this one

Answer Source

You need to get data first and then update:

$data = IsiSJKirim::where('IsiSJKir', $isisjkir[$key])->first();
$data->update(['QSisaKemInsert' => (int)$data->QSisaKemInsert + (int)$qtertanda[$key]]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download