/** * Display the specified resource. * * @param int $id * @return Response */ public function show(Category $category, Request $request) { $deleted_device = Device::onlyTrashed()->where('category_id', $category->id)->get(); $devices = Device::with(['information.field', 'owner', 'status'])->where('category_id', $category->id)->latest('updated_at'); if ($request->has('filter')) { $device_filter = $devices->where('name', 'LIKE', '%' . $request->get('filter') . '%')->get(); if (count($device_filter) == 0) { $first_name_filter = Device::whereHas('owner', function ($q) use($request) { $q->where('firstName', 'LIKE', '%' . $request->get('filter') . '%'); })->get(); if (count($first_name_filter) == 0) { $devices = Device::whereHas('owner', function ($q) use($request) { $q->where('lastName', 'LIKE', '%' . $request->get('filter') . '%'); }); } else { $devices = Device::whereHas('owner', function ($q) use($request) { $q->where('firstName', 'LIKE', '%' . $request->get('filter') . '%'); }); } } else { $devices = $devices->where('name', 'LIKE', '%' . $request->get('filter') . '%'); } } $devices = $devices->paginate(25); //$devices = $devices->where('name', 'LIKE', '%'.$request->get('filter').'%')->paginate(25); $devices->setPath($category->slug); return view('category.show', compact('category', 'deleted_device', 'devices')); }
public function info($device_id) { $header = app('request')->header(); if (!$this->check($header)) { return response('Unauthorized', 401); } $device = Device::with('local')->find($device_id); $mappings = Mapping::with(array('type', 'standard'))->where('device_id', '=', $device_id)->get(); $device->mappings = $mappings; return $device; }
// 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); });
public static function editInformation($device_slug) { $device = Device::with(['information'])->whereSlug($device_slug)->first(); return view('devices.edit_information', compact('device')); }
public function index() { $devices = Device::with('modele.category', 'modele.brand')->get(); $leftmenu['devices'] = 'active'; return view('/devices/index', ['leftmenu' => $leftmenu, 'devices' => $devices]); }
public function device($device_id) { $data = Device::with('mapping')->where('id', '=', $device_id)->get(); return $data; }