/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Requests\DeviceRequest $request) { // $data = $request->except('_token'); Device::create($data); return back(); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $user = User::create(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'car_brand' => $data['car_brand'], 'car_color' => $data['car_color']]); for ($i = 1; $i <= $data['package']; ++$i) { $device = Device::create(['device_nr' => $data['device_nr'] . '-' . $i]); $user->devices()->save($device); } $user->save(); return $user; }
public function addNewDevice(Request $request) { //store device in database $inputDeviceName = $request->input('inputDeviceName'); $inputDeviceIP = $request->input('inputDeviceIP'); $inputDeviceComPass = $request->input('inputDeviceComPass'); $device = Device::create(['device_name' => $inputDeviceName, 'ip_address' => $inputDeviceIP, 'com_key' => $inputDeviceComPass]); $device->save(); return redirect()->action('HomeController@index'); }
/** * Update the specified resource in storage. * * @param ProfileRequest|Request $request * @param int $id * @return Response */ public function update(ProfileRequest $request, $id) { $user = $this->authUser; $user->update($request->all()); $q = $request->get('quantity'); for ($i = 1; $i <= $q; ++$i) { $device = Device::create(['device_nr' => $request->get('device_nr') . '-' . $i]); $user->devices()->save($device); } $user->save(); Session::flash('message', 'You have successfully updated your profile.'); Session::flash('alert-class', 'alert-success'); return redirect()->back(); }
public function auth(Request $request) { $device_id = $request->device_id; $usernameinput = $request->email; $password = $request->pwd; $version = $request->version; // dd($request); $field = $usernameinput ? 'email' : 'username'; if (\Auth::attempt(array('username' => $usernameinput, 'password' => $password), false)) { $user = \Auth::user(); $device = Device::where('device_id', $device_id)->first(); if ($request->has('version')) { if (!empty($device)) { $device->version = $version; $device->username = $usernameinput; $device->update(); } else { Device::create(['device_id' => $device_id, 'version' => $version, 'username' => $usernameinput]); } } if ($user->log_status == 0 || $user->device_id == $device_id) { $user->log_status = 1; $user->device_id = $device_id; $user->last_login = date('Y-m-d H:i:s'); $user->update(); $hash = UpdateHash::find(1); $user->hash = $hash->hash; return response()->json($user); } else { $t1 = StrToTime(date('Y-m-d H:i:s')); $t2 = StrToTime($user->last_login); $diff = ($t1 - $t2) / (60 * 60); if ($diff >= 24) { $user->log_status = 1; $user->device_id = $device_id; $user->last_login = date('Y-m-d H:i:s'); $user->update(); $hash = UpdateHash::find(1); $user->hash = $hash->hash; return response()->json($user); } else { return response()->json(array('msg' => 'User already logged on another device.', 'status' => 0, 'hr' => $diff)); } } } else { return response()->json(array('msg' => 'user not found', 'status' => 0)); } }
foreach ($data['live'] as $device) { foreach ($device->sensors as $sensor) { // $points['arduino1']['2015-07-19 14:30']['humedad1'] = 35 //$points[$device->name]['by_date'][$sensor->created_at->toDateTimeString()][$sensor->type] = $sensor->value; // $points['arduino1']['humedad1'][] = ['2015-07-19 14:30', 35] $points[$device->name][$sensor->type][] = [$sensor->created_at->timestamp, $sensor->value]; } } // 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('/');