Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function postUpload ()
- {
- if ( Input::hasFile('file') )
- {
- DB::transaction(function()
- {
- // Clear out what we have written
- DB::table('wc_program')->delete();
- $csv = new CsvFile(Input::file('file')->getRealPath());
- // Get the csv headers and move to the next line (the start of actual data)
- $columns = $csv->getHeader();
- $csv->next();
- // Loop through the rows creating / saving a record for each
- while( $csv->valid() )
- {
- $row = $csv->current();
- $pc = new Programmes();
- for( $i=0; $i<count($columns); $i++ )
- {
- $pc->$columns[$i] = $row[$i];
- }
- $pc->save();
- $csv->next();
- }
- });
- return Redirect::to('admin/programmes')->with('flash_success', 'Upload completed & new data inserted.');
- }
- class Programmes extends Eloquent {
- protected $guarded = array('id');
- //public static $rules = array();
- protected $table = 'wc_program_1';
- public $timestamps = false;
- }
- Route::get('admin/programmes/excelUpload','ProgrammesController@excelUpload');
- Route::post('admin/programmes/doUpload', ['as' => 'admin.programmes.doUpload', 'uses' => 'ProgrammesController@postUpload']);
- $pc->$columns[$i] = $row[$i];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement