I have a edit form which edit an array like (Invoice) , I want when i edit the Invoice_no a can also able to add the new item on the same invoice number
Example the Inv_no=300 and its carry 3 arrays ([... .... ... ]), so I want to add the new one array to be 4 arrays.
On my code below is update array well data but if i add new one row does not save that new one while it keep update,
what can i do here to add/save the new one data.
public function update(Request $request, $inv_no)
{
$data = $request->all();
//dd($data);
$stocks = Stock::where('inv_no', $inv_no)->get();
$i = 0;
foreach ($stocks as $stock) {
Stock::where('inv_no', $inv_no)
->where('id', $stock->id)
->update([
'pid' => $request->pid[$i],
'qty' => $request->qty[$i],
'inv_no' => $request->inv_no,
'user_id' => Auth::user()->id,
'Indate'=>$request->Indate,
'supplierName' => $request->supplierName,
'receiptNumber' => $request->receiptNumber,
'truckNumber' => $request->truckNumber,
'driverName' => $request->driverName,
'remark' => $request->remark,
]);
$i++;
}
return $this->index();
}
updateOrCreate()?