I have a function in controller where multiple row from a form is being saved it looks like this ,
public function postPayment(PaymentRequest $request){
$insertPayment=Input::get();
$payment= new paymentrecieved();
$data=array();
for($i = 0; $i < count($insertPayment['recieved_amount']); $i++) {
if($insertPayment['adjustmentmode'][$i]=='Option')
$adjust_mode='NONE';
else
$adjust_mode=$insertPayment['adjustmentmode'][$i];
$payment->invoice_id=$insertPayment['invoiceid'];
$payment->recieved_amount = $insertPayment['recieved_amount'][$i];
$payment->refno = $insertPayment['ref_no'][$i];
$payment->date = $insertPayment['date'][$i];
$payment->adjust_amount = $insertPayment['adjustmentamount'][$i];
$payment->adjust_mode= $adjust_mode;
$payment->save();
}
// $result = paymentrecieved::create($data);
$this->saveComment($insertPayment['comment'],$insertPayment['date1'],$insertPayment['invoiceid']);
$request->session()->flash('alert-success', 'Payment Has Been inserted Successfully');
return redirect('collection/payment/'.$insertPayment['invoiceid'].'');
}
So in the loop I am trying to save multiple row , But only the last row of the form is being saved i n my database . Any leads on what could be the issue .
Thanks