public function destroy($id)
 {
     //find and delete the scan user
     $destroyUser = ScansUser::find($id);
     $destroyUser->delete();
     //return the user
     return $destroyUser->toJSON();
 }
 /**
  * Auto generated seed file
  *
  * @return void
  */
 public function run()
 {
     \DB::table('virus_users')->delete();
     $faker = Faker\Factory::create();
     foreach (range(1, 5) as $id) {
         ScansUser::create(['user_name' => $faker->name()]);
     }
 }
 public function update($id)
 {
     //get the json from the request.
     $updateModel = Input::json()->all();
     //update the scan model based on the json data sent.
     $updateScan = Scans::find($id);
     $updateScan->mac_addr = $updateModel['mac_addr'];
     $updateScan->scan_date = $updateModel['scan_date'];
     $updateScan->room_number = $updateModel['room_number'];
     $updateScan->cpu_desc = $updateModel['cpu_desc'];
     $updateScan->troj_mal = $updateModel['troj_mal'];
     $updateScan->pups = $updateModel['pups'];
     $updateScan->notes = $updateModel['notes'];
     $updateScan->scanned_by = $updateModel['scanned_by'];
     //if the user doesn't exist, it makes a new user. Otherwise, it gets the user for this scan
     $scanUser = ScansUser::where('user_name', '=', $updateModel['user_name'])->first();
     if ($scanUser == null) {
         $scanUser = new ScansUser();
         $scanUser->user_name = $updateModel['user_name'];
         $scanUser->save();
     }
     //if the user for the update and the old user are different, then update each one
     if ($updateScan->uid != $scanUser->id) {
         $oldScanUser = $updateScan->getScansUserById();
         $updateScan->uid = $scanUser->id;
         $updateScan->save();
         $oldScanUser->updateTotal();
         $oldScanUser->updateMostRecentScan();
         $scanUser->updateTotal();
         $scanUser->updateMostRecentScan();
     } else {
         //if its still the same user, just update the one person
         $updateScan->save();
         $scanUser->updateTotal();
         $scanUser->updateMostRecentScan();
     }
     //send the response
     return $updateScan->toJson();
 }
Exemple #4
0
 public function getScansUserById()
 {
     return ScansUser::where('id', '=', $this->uid)->firstOrFail();
 }