public function postsitedata() { $file = Input::file('sitedata'); $destinationPath = 'importdata'; // If the uploads fail due to file system, you can try doing public_path().'/uploads' $filename = 'imported-sitedata'; //$filename = $file->getClientOriginalName(); //$extension =$file->getClientOriginalExtension(); $upload_success = Input::file('sitedata')->move($destinationPath, $filename . '.' . $file->getClientOriginalExtension()); if ($upload_success) { $importedFile = public_path() . '/importdata/' . $filename . '.' . $file->getClientOriginalExtension(); Excel::load($importedFile, function ($r) { $res = $r->all()->toArray(); foreach ($res as $data) { if ($data['site'] != '' && $data['site_id'] != '') { $d = new Mastertp(); $d->sitelocation = $data['site']; $d->btsnameoss = $data['site_id']; $d->save(); } } }); Session::flash('success', 'Data imported to database'); return Redirect::to('/import'); } else { Session::flash('error', 'Error uploading files'); return Redirect::to('/import'); } }
function storefromajax() { $mastertp = new Mastertp(); $mastertp->sitelocation = Input::get('namasite'); $mastertp->btsname = Input::get('namabts'); $mastertp->save(); return Response::json($mastertp); }
public function importmastertp() { $ext = Input::file('file')->getClientOriginalExtension(); $validator = Validator::make(array('ext' => $ext), array('ext' => 'in:xls,xlsx')); if ($validator->fails()) { Session::flash('error', 'File format tidak di dukung'); return Redirect::to('/admin/import/mastertp'); } else { if ($ext == 'xls') { Input::file('file')->move(public_path(), 'mastertp.xls'); if (Input::get('replace') == 'on') { DB::table('mastertp')->delete(); } else { } try { Excel::load('public/mastertp.xls', function ($r) { $res = $r->all()->toArray(); foreach ($res as $data) { $d = new Mastertp(); if ($data['site'] != '' && $data['site_id'] != '') { $d->sitelocation = $data['site']; $d->btsname = $data['site_id']; $d->save(); } } }); } catch (Exception $e) { Session::flash('error', '' . $e->getMessage()); return Redirect::to('/admin/import/mastertp'); } } elseif ($ext == 'xlsx') { Input::file('file')->move(public_path(), 'mastertp.xlsx'); if (Input::get('replace') == 'on') { DB::table('mastertp')->delete(); } else { } try { Excel::load('public/mastertp.xlsx', function ($r) { $res = $r->all()->toArray(); foreach ($res as $data) { $d = new Mastertp(); if ($data['site'] != '' && $data['site_id'] != '') { $d->sitelocation = $data['site']; $d->btsname = $data['site_id']; $d->save(); } } }); } catch (Exception $e) { Session::flash('error', '' . $e->getMessage()); return Redirect::to('/admin/import/mastertp'); } } else { } Session::flash('success', 'Data telah dibuat.'); return Redirect::to('/admin/import/mastertp'); } }