public static function update_information($request) { $info_val = $request->get('value'); $info_id = $request->get('inf_id'); $device_id = $request->get('device_id'); Information::find($info_id)->update(['value' => $info_val]); $device = Device::find($device_id); $device->touch(); return redirect()->back(); }
public function recordActivity($event) { $model = strtolower(class_basename($this)); if ($event == "created") { $activity = new Activity(); $activity->subject_id = $this->id; $activity->subject_type = get_class($this); $activity->name = $this->getActivityName($this, $event); $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; if ($model == "category") { $activity->old_value = $this->name; } elseif ($model == "information") { $activity->old_value = $this->value; } elseif ($model == "field") { $activity->old_value = $this->category_label; } elseif ($model == "devicelog") { $activity->old_value = $this->action; } elseif ($model == "owner") { $activity->old_value = $this->fullName(); } else { $activity->old_value = $this->name; } $activity->save(); } elseif ($event == "updates") { if ($model == "category") { $activity = new Activity(); $activity->subject_id = $this->id; $activity->subject_type = get_class($this); $activity->name = $this->getActivityName($this, $event); $activity->old_value = $this->name; $activity->new_value = Input::get('name'); $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; $activity->save(); $this->name = Input::get('name'); $this->save(); } elseif ($model == "device") { $activity = new Activity(); $activity->subject_id = $this->id; $activity->subject_type = get_class($this); $activity->name = $this->getActivityName($this, $event); $activity->old_value = $this->name; $activity->new_value = Input::get('phone_number'); $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; $activity->save(); $this->phone_number = Input::get('name'); $this->save(); } elseif ($model == "information") { foreach (Input::all() as $key => $value) { if (strpos($key, 'info') !== false) { $key = explode('-', $key); $info_id = $key[1]; $activity = new Activity(); $information = Information::find($info_id); $activity->subject_id = $information->id; $activity->subject_type = get_class($information); $activity->name = $information->getActivityName($information, $event); $activity->old_value = $information->value; $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; $activity->save(); $information->value = $value; $information->save(); $act = Activity::find($activity->id); $act->new_value = $information->value; $act->save(); } } } } elseif ($event == "deleted") { $activity = new Activity(); $activity->subject_id = $this->id; $activity->subject_type = get_class($this); $activity->name = $this->getActivityName($this, $event); $activity->user_id = Auth::guest() ? 0 : Auth::user()->id; if ($model == "field") { $activity->old_value = $this->category_label; } elseif ($model == "information") { $activity->old_value = $this->value; } else { $activity->old_value = $this->name; } $activity->save(); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Request $request) { $user = Information::find($request->input('id')); $user->delete(); return "User record successfully deleted #" . $request->input('id'); }