I have a form for adding cheques to a system. The form has two parts; part one is for the common info i.e the customer details and part two is for the unique details i.e cheque details. Multiple cheques can be added for the same user by clicking an Add button which generates duplicate inputs for the form. While saving the data on mysql database using Laravel, i got the error
"Undefined offset: 1"
Here is my laravel controller :
public function store(Request $request)
{
$customer_name = $request->customer_name;
$cheque_number=$request->cheque_number;
$count = count($cheque_number);
for($i = 0; $i < $count; $i++){
$objModel = new Cheque();
$objModel->customer_name = $customer_name[$i];
$objModel->cheque_number = $cheque_number[$i];
$objModel->save();
}
}
My main challenge is each cheque number should be saved on a new row, but with the same customer name which is provided only once.