I'm using a package > http://csv.thephpleague.com/
But I'm getting a Undefined offset: 1 when uploading, although the CSV does upload and works this error is thrown which obviously I don't the client see or think there's a problem.
Here's the method in question:
public function postUpload()
{
$file = Input::file('file');
$name = time() . '-' . $file->getClientOriginalName();
$moved = $file->move(public_path() . '/uploads/CSV', $name);
DB::table('wc_program_1')->truncate();
$csv = new Reader($moved);
$csv->setOffset(0); //because we don't want to insert the header
$nbInsert = $csv->each(function ($row) use (&$sth) {
DB::table('wc_program_1')->insert(
array(
'Road' => $row[0],
'Parish' => $row[1],
'WorkType' => $row[2],
'TrafficManagement' => $row[3],
'Duration' => $row[4],
'Start' => $row[5]
)
);
return true;
});
return Redirect::to('admin/programmes')->with('flash_success', 'Upload completed & new data inserted.');
}
And here the table structure:
