Undefined offset: 4 in Laravel
when I click on submit button then other empty rows should be ignored.
controller.php
function commundityvendordata(Request $request){
$collection = count(collect($request));
// Insert data into database
$cvendordata = new commundityvendordata;
for ($i=0; $i < $collection; $i++) {
$new_date = $request->new_date;
$CCode=communitydata::where('c_code','=',$request->ccode[$i])->first();
$cd_id = $CCode['cd_id'];
$CName=communitydata::where('c_name','=',$request->cname[$i])->first();
$cd_id = $CName['cd_id'];
$CUnit=units::where('unit','=',$request->cunit[$i])->first();
$unit_id = $CUnit['unit_id'];
$vender1 = $request->vendor1[$i];
$vender2 = $request->vendor2[$i];
$vender3 = $request->vendor3[$i];
$vender4 = $request->vendor4[$i];
$commdata = [
'new_date' => Carbon::parse($new_date)->format('Y-m-d'),
'cd_id' => $cd_id,
'cn_id' => $cd_id,
'unit_id' => $unit_id,
'vender1' => $vender1,
'vender2' => $vender2,
'vender3' => $vender3,
'vender4' => $vender4
];
DB::table('commundityvendordata')->insert($commdata);
}
return back()->with('success','Data Saved...');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire