'How to subtract quantity from the equipment table when there's a new borrow transaction made?
I'm a Laravel newbie and I recently started working on a equipment management system whereby the admin adds quantity stock one each equipment to the system and when admin let the user borrow the equipment it deducts the quantity that the user wants from the equipment stock table. My only challenge is how to make the system to subtract quantity that the borrower wants from the equipment stock table?
Here's my controller for the button "borrow" So when I click the borrow button it will deducts the ('quantity_item') to the equipment stock table ('e_quantity')
public function borrow($id){
$first = Reservation::where('id', $id)->first();
$kl = $first->name;
$mn = $first->Name_item;
$st = $first->quantity_item; //this is the quantity that the borrower wants
$op = $first->dt_item;
$qr = $first->room_item;
$first->delete();
$second = new BorrowedItems();
$second->bname = $kl;
$second->bdate = $mn;
$second->itemb = $op;
$second->bquantity = $st;
$second->broom = $qr;
$second->save();
return redirect()->back()->with('message','Item Borrowed Successfully!');
}
This is my Equipment Stock Table

This is my BorrowedItem Table
so when I click the borrow button the data from reservationtable will transfer here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|




