I have a table named bills. in the table one field is amount and another field is bill_amount_left. I want to sum up the bill_amount_left when a new bill is added. If a bill is created against an user then, users previous bill_amount_left will be automatically increased with the new bill. How to do that?
$data = $this->validate([
'property_id' => 'required',
'amount' => 'required',
'due_date' => 'required',
'start_date' => 'required',
'end_date' => 'required',
'bill_type' => 'required',
'remark' => 'required',
]);
$data['amount_left'] = $data['amount'];
$bill = Bill::create($data);
I am using these code to create a bill. So, I need to update the amount_left field every time a new bill is created. Also I need to identify against which property they bill is created. For example a bill is created against property_id 1. Then another bill created against property_id 1. So the field amount_left should automatically increased with newly created bill.