Skip to content

Instantly share code, notes, and snippets.

@talha08
Created June 8, 2017 18:32
Show Gist options
  • Save talha08/222c4374b5307702abfbddb89054e3e8 to your computer and use it in GitHub Desktop.
Save talha08/222c4374b5307702abfbddb89054e3e8 to your computer and use it in GitHub Desktop.
CSV to Database Laravel
Route::get ( '/', function () {
if (($handle = fopen ( public_path () . '/MOCK_DATA.csv', 'r' )) !== FALSE) {
while ( ($data = fgetcsv ( $handle, 1000, ',' )) !== FALSE ) {
$csv_data = new Csvdata ();
$csv_data->id = $data [0];
$csv_data->firstname = $data [1];
$csv_data->lastname = $data [2];
$csv_data->email = $data [3];
$csv_data->gender = $data [4];
$csv_data->save ();
}
fclose ( $handle );
}
$finalData = $csv_data::all ();
return view ( 'welcome' )->withData ( $finalData );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment