/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $backups = DeviceBackup::orderBy('updated_at', 'desc')->get();
     return view('backup.index', compact('backups'));
 }
 public function backuplist($user)
 {
     $username = $user;
     $id = DeviceBackup::where('username', $username)->first();
     $filename = BackupList::where('device_backup_id', $id->id)->get();
     // foreach ($filename as $value) {
     // $fname[]= $value->filename;
     // }
     //         $backups = [];
     // foreach ($fname as $f) {
     //         $filesInFolder[]  = storage_path().'/uploads/backups/' . $f;
     // }
     //   foreach($filesInFolder as $path)
     // {
     //     $backups[] = pathinfo($path)['basename'];
     // }
     // foreach ($backups as $b) {
     //         $time = backup_list::where('filename',$b)->get();
     // }
     //     foreach ($time as $t) {
     //     }
     // if(count($backups)>0){
     //     return response()->json(array('msg' => 'Backup files lists.', 'files' => $backups));
     // }
     if (count($filename) > 0) {
         return response()->json(array('msg' => 'Backup files lists.', 'files' => $filename));
     } else {
         # code...
         return response()->json(array('msg' => 'No files found'));
     }
 }
 public function uploadbackup(Request $request)
 {
     if ($request->hasFile('data')) {
         $time = date('His', strtotime(Carbon::now()));
         $date = date('mdY');
         $destinationPath = storage_path() . '/uploads/backups/';
         $filename = "pcountDB_" . $date . "_" . $time;
         $file_path = $request->file('data')->move($destinationPath, $filename);
         $device_id = $request->device_id;
         $username = $request->username;
         $database_version = $request->database_version;
         $dbackup = DeviceBackup::firstOrCreate(['username' => $username]);
         if ($dbackup->device_id == "") {
             $dbackup->device_id = $device_id;
             $dbackup->update();
         } else {
             $dbackup->device_id = $device_id;
             $dbackup->update();
         }
         $list = BackupList::where('filename', $filename)->where('device_backup_id', $dbackup->id)->first();
         if (!empty($list)) {
             $list->updated_at = date('Y-m-d H:i:s');
             $list->database_version = $database_version;
             $list->update();
         } else {
             BackupList::create(['filename' => $filename, 'device_backup_id' => $dbackup->id, 'database_version' => $database_version]);
         }
         return response()->json(array('msg' => 'Backup successfully submitted.', 'status' => 0));
     }
     return response()->json(array('msg' => 'Failed in submitting backup.', 'status' => 1));
 }