/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $device = Device::find($id); $device->update($request->except(['_token', '_method'])); return redirect()->to('devices'); }
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(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $devices = Device::all(); $connected_device = Device::find(1); if (Connected::find(1) == null) { $connected_device = Connected::Create(['ip_address' => '127.0.0.1', 'device_id' => 0, 'connected' => 0]); } $connected_device = Connected::find(1); return view('pages.home', compact('devices', 'connected_device')); // ->with(['devices' => $devices, 'conne']); }
public function chart($device_id, $type_id) { $header = app('request')->header(); if (!$this->check($header)) { return response('Unauthorized', 401); } $chart = Device::find($device_id); $chart->standard = Standard::with('type')->where('type_id', '=', $type_id)->get(); $chart->chart = Convert::select(DB::raw('*, HOUR(timestamp) as hour'))->where('device_id', '=', $device_id)->where('type_id', '=', $type_id)->whereRaw('DATE(timestamp) = CURDATE()')->groupBy('hour')->get(); $chart->threshold = Mapping::select('min_threshold', 'max_threshold')->where('device_id', '=', $device_id)->where('type_id', '=', $type_id)->get(); return $chart; }
// pasamos los datos a la vista para allí pasarlo al JS $data['toJavascript']['points'] = $points; return view('dashboard')->with($data); }); Route::get('store/{name}', function ($name) { $input = Request::only('temperatura', 'luz', 'humedad1', 'humedad2', 'humedad3', 'humedad4'); if (!($device = Device::find($name))) { $device = App\Device::create(['name' => $name]); $device->save(); $device->name = $name; $device = Device::find($name); } foreach ($input as $type => $value) { if ($value != null) { $sensor = new App\Sensor(['type' => $type, 'value' => $value]); $device->sensors()->save($sensor); } } return Device::with('sensors')->find($name); }); Route::get('devices/{name}', function ($name) { if (!($device = Device::find($name))) { return redirect('/'); } foreach ($device->sensors as $sensor) { $points[$device->name][$sensor->type][] = [$sensor->created_at->timestamp, $sensor->value]; } $data['device'] = $device; $data['toJavascript']['points'] = $points; return view('device')->with($data); });
/** * Delete device * * @param [int] $id * @return Response */ public function delete($id) { $device = Device::find($id); $device->delete(); return redirect()->route('devices.index')->with('messageDelete', 'Delete device successfully!'); }
public static function disassocLog($id) { $device = Device::find($id); $device_log = new DeviceLog(); $device_log->owner_id = $device->owner_id; $device_log->device_id = $id; $device_log->user_id = \Auth::user()->id; $device_log->action = "DISASSOCIATE"; $device_log->save(); $owner_id = $device_log->owner_id; $owner = Owner::find($owner_id); $device->owner_id = 0; $device->save(); return redirect()->back()->with('success_msg', $device->name . ' was DISASSOCIATED to ' . $owner->fullName())->with('message_label', 'alert-success'); }
/** * Save information of device be assigned to * * @param Request $request * @return void */ public function save(Request $request) { $data = Request::input('data'); Device::find($data['id'])->update($data); }
public function deleteData(Request $request) { $parameter = $request->input('parameter'); $local = $request->input('local'); $data = json_decode($request->input('data')); $local = Local::where('name', '=', $local)->get(); switch ($parameter) { case 'device': $device = Device::find((int) $data->id + (int) $local[0]->constant); $device->delete(); break; case 'mapping': $mapping = Mapping::find((int) $data->id + (int) $local[0]->constant); $mapping->delete(); break; default: break; } return 'true'; }
public function delete(Request $request) { $path = config('path'); $device_id = $request->input('device_id'); $delete_device = Device::find($device_id); $result = shell_exec('python ' . $path . 'publish.py /delete/device/' . config('local') . ' ' . escapeshellarg(json_encode($delete_device))); $delete_device->delete(); return "true"; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($device, Request $request) { $return_device = Device::find($device->id); $device = $return_device->name; $return_device->delete(); $category_slug = $request->get('category_slug'); return redirect(route('category.show', [$category_slug]))->with('success_msg', 'Device :: ' . $device . ' was successfully deleted'); }