public function store() { // get all inputs $addModel = Input::json()->all(); //create a new scan and set attributes to inputs $addScan = new Scans(); $addScan->mac_addr = $addModel['mac_addr']; $addScan->scan_date = $addModel['scan_date']; $addScan->room_number = $addModel['room_number']; $addScan->cpu_desc = $addModel['cpu_desc']; $addScan->troj_mal = $addModel['troj_mal']; $addScan->pups = $addModel['pups']; $addScan->notes = $addModel['notes']; $addScan->scanned_by = $addModel['scanned_by']; //if the user doesn't exist, it makes a new user $scanUser = ScansUser::where('user_name', '=', $addModel['user_name'])->first(); if ($scanUser == null) { $scanUser = new ScansUser(); $scanUser->user_name = $addModel['user_name']; $scanUser->save(); } //sets the uid fof scan user $addScan->uid = $scanUser->id; $addScan->save(); //returns the scan return $addScan->toJson(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Scans(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Scans'])) { $model->attributes = $_POST['Scans']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }