Пример #1
0
 /**
  * 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'));
 }
Пример #2
0
 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;
 }
Пример #3
0
    // 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);
});
Пример #4
0
 public static function editInformation($device_slug)
 {
     $device = Device::with(['information'])->whereSlug($device_slug)->first();
     return view('devices.edit_information', compact('device'));
 }
Пример #5
0
 public function index()
 {
     $devices = Device::with('modele.category', 'modele.brand')->get();
     $leftmenu['devices'] = 'active';
     return view('/devices/index', ['leftmenu' => $leftmenu, 'devices' => $devices]);
 }
Пример #6
0
 public function device($device_id)
 {
     $data = Device::with('mapping')->where('id', '=', $device_id)->get();
     return $data;
 }