@@ -15,12 +15,12 @@ |
||
| 15 | 15 | public function dataTable($query) |
| 16 | 16 | { |
| 17 | 17 | return datatables($query) |
| 18 | - ->editColumn('sensor_id', function ($sensordata) { |
|
| 19 | - return '<a href="/sensor/' . $sensordata->sensor_id . '">'. $sensordata->sensor->name . '</a>'; |
|
| 18 | + ->editColumn('sensor_id', function($sensordata) { |
|
| 19 | + return '<a href="/sensor/'.$sensordata->sensor_id.'">'.$sensordata->sensor->name.'</a>'; |
|
| 20 | 20 | }) |
| 21 | 21 | ->addColumn('action', 'sensordata.action') |
| 22 | - ->blacklist([ 'action']) |
|
| 23 | - ->rawColumns(['sensor_id', 'action']); |
|
| 22 | + ->blacklist([ 'action' ]) |
|
| 23 | + ->rawColumns([ 'sensor_id', 'action' ]); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function index() |
| 23 | 23 | { |
| 24 | - return response()->json(['data' => 'SmartSettia API - Bad request type.'], 400); |
|
| 24 | + return response()->json([ 'data' => 'SmartSettia API - Bad request type.' ], 400); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | // If validation fails, send the validation error back with status 400. |
| 67 | 67 | if ($validator->fails()) { |
| 68 | - return response()->json(['data' => $validator->errors()], 400); |
|
| 68 | + return response()->json([ 'data' => $validator->errors() ], 400); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // Get the device record. |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | // If token doesnt match then send 401 unauthorized. |
| 75 | 75 | if ($request->input('token') != $device->token) { |
| 76 | - return response()->json(['data' => 'Bad token.'], 401); |
|
| 76 | + return response()->json([ 'data' => 'Bad token.' ], 401); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // Update the device. |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | //event(new Registered(true)); |
| 101 | 101 | |
| 102 | 102 | // Return the new device info including the token. |
| 103 | - return response()->json(['data' => $device->toArray()], 201); |
|
| 103 | + return response()->json([ 'data' => $device->toArray() ], 201); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | // If validation fails, send the validation error back with status 400. |
| 124 | 124 | if ($validator->fails()) { |
| 125 | - return response()->json(['data' => $validator->errors()], 400); |
|
| 125 | + return response()->json([ 'data' => $validator->errors() ], 400); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Get the device record. |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | // If token doesnt match then send 401 unauthorized. |
| 132 | 132 | if ($request->input('token') != $device->token) { |
| 133 | - return response()->json(['data' => 'Bad token.'], 401); |
|
| 133 | + return response()->json([ 'data' => 'Bad token.' ], 401); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Update the device. |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | foreach ($sensor_datas as $sensor_data) { |
| 148 | 148 | $sensor = Sensor::firstOrCreate([ |
| 149 | 149 | "device_id" => $device->id, |
| 150 | - "name" => $sensor_data['name'], |
|
| 151 | - "type" => $sensor_data['type'] |
|
| 150 | + "name" => $sensor_data[ 'name' ], |
|
| 151 | + "type" => $sensor_data[ 'type' ] |
|
| 152 | 152 | ]); |
| 153 | 153 | |
| 154 | 154 | SensorData::create([ |
| 155 | 155 | "sensor_id" => $sensor->id, |
| 156 | - "value" => $sensor_data['value'] |
|
| 156 | + "value" => $sensor_data[ 'value' ] |
|
| 157 | 157 | ]); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | //event(new Registered(true)); |
| 164 | 164 | |
| 165 | 165 | // Return the new device info including the token. |
| 166 | - return response()->json(['data' => $device->toArray()], 201); |
|
| 166 | + return response()->json([ 'data' => $device->toArray() ], 201); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -182,12 +182,12 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | // If validation fails, send the validation error back with status 400. |
| 184 | 184 | if ($validator->fails()) { |
| 185 | - return response()->json(['data' => $validator->errors()], 400); |
|
| 185 | + return response()->json([ 'data' => $validator->errors() ], 400); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // If challenge string doesnt match then send 401 unauthorized. |
| 189 | 189 | if ($request->input('challenge') != env('API_CHALLENGE', 'temppass')) { |
| 190 | - return response()->json(['data' => 'Bad challenge.'], 401); |
|
| 190 | + return response()->json([ 'data' => 'Bad challenge.' ], 401); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // If the uuid already exists then just send them the record. |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | 'uuid' => $device->uuid, |
| 198 | 198 | 'id' => $device->id, |
| 199 | 199 | 'token' => $device->token, |
| 200 | - ]], 200); |
|
| 200 | + ] ], 200); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // Create the new device. |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | 'uuid' => $device->uuid, |
| 222 | 222 | 'id' => $device->id, |
| 223 | 223 | 'token' => $device->token, |
| 224 | - ]], 201); |
|
| 224 | + ] ], 201); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | // If validation fails, send the validation error back with status 400. |
| 242 | 242 | if ($validator->fails()) { |
| 243 | - return response()->json(['data' => $validator->errors()], 400); |
|
| 243 | + return response()->json([ 'data' => $validator->errors() ], 400); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // Get the device record. |
@@ -248,25 +248,25 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | // If token doesnt match then send 401 unauthorized. |
| 250 | 250 | if ($request->input('token') != $device->token) { |
| 251 | - return response()->json(['data' => 'Bad token.'], 401); |
|
| 251 | + return response()->json([ 'data' => 'Bad token.' ], 401); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // Save the image to disk. |
| 255 | - $path = $request->file('image')->storeAs('deviceimage', $device['id'], 'private'); |
|
| 255 | + $path = $request->file('image')->storeAs('deviceimage', $device[ 'id' ], 'private'); |
|
| 256 | 256 | |
| 257 | 257 | // Update the url for the image. |
| 258 | 258 | $deviceimage = Deviceimage::updateOrCreate( |
| 259 | - ['device_id' => $device['id']], |
|
| 260 | - ['url' => $path] |
|
| 259 | + [ 'device_id' => $device[ 'id' ] ], |
|
| 260 | + [ 'url' => $path ] |
|
| 261 | 261 | ); |
| 262 | 262 | |
| 263 | 263 | // Force the updated_at timestamp to update as the url may not change. |
| 264 | 264 | $deviceimage->touch(); |
| 265 | 265 | |
| 266 | 266 | return response()->json([ 'data' => [ |
| 267 | - 'id' => $deviceimage['id'], |
|
| 267 | + 'id' => $deviceimage[ 'id' ], |
|
| 268 | 268 | 'url' => $path, |
| 269 | - ]], 201); |
|
| 269 | + ] ], 201); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |