@@ -64,7 +64,7 @@ |
||
| 64 | 64 | /** |
| 65 | 65 | * Get columns. |
| 66 | 66 | * |
| 67 | - * @return array |
|
| 67 | + * @return string[] |
|
| 68 | 68 | */ |
| 69 | 69 | protected function getColumns() |
| 70 | 70 | { |
@@ -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 | /** |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Creates a json response for all the devices. |
| 19 | 19 | * |
| 20 | - * @return Response |
|
| 20 | + * @return \Illuminate\Http\JsonResponse |
|
| 21 | 21 | */ |
| 22 | 22 | public function index() |
| 23 | 23 | { |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * Creates a json response for a specifc device. |
| 29 | 29 | * |
| 30 | 30 | * @param Device $device |
| 31 | - * @return Response |
|
| 31 | + * @return \Illuminate\Http\JsonResponse |
|
| 32 | 32 | */ |
| 33 | 33 | public function show(Device $device) |
| 34 | 34 | { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * Updates the status of a device. |
| 40 | 40 | * |
| 41 | 41 | * @param Request $request |
| 42 | - * @return Response |
|
| 42 | + * @return \Illuminate\Http\JsonResponse |
|
| 43 | 43 | */ |
| 44 | 44 | public function update(Request $request) |
| 45 | 45 | { |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * Updates the sensors of a device. |
| 108 | 108 | * |
| 109 | 109 | * @param Request $request |
| 110 | - * @return Response |
|
| 110 | + * @return \Illuminate\Http\JsonResponse |
|
| 111 | 111 | */ |
| 112 | 112 | public function sensor(Request $request) |
| 113 | 113 | { |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * Registers a new device. |
| 171 | 171 | * |
| 172 | 172 | * @param Request $request |
| 173 | - * @return Response |
|
| 173 | + * @return \Illuminate\Http\JsonResponse |
|
| 174 | 174 | */ |
| 175 | 175 | public function register(Request $request) |
| 176 | 176 | { |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | * Updates the image for a device. |
| 229 | 229 | * |
| 230 | 230 | * @param Request $request |
| 231 | - * @return Response |
|
| 231 | + * @return \Illuminate\Http\JsonResponse |
|
| 232 | 232 | */ |
| 233 | 233 | public function image(Request $request) { |
| 234 | 234 | // Validate the request. |
@@ -9,8 +9,6 @@ |
||
| 9 | 9 | use App\User; |
| 10 | 10 | use App\Sensor; |
| 11 | 11 | use App\SensorData; |
| 12 | -use Illuminate\Support\Facades\Cache; |
|
| 13 | -use Illuminate\Support\Facades\Storage; |
|
| 14 | 12 | |
| 15 | 13 | class ApiController extends Controller |
| 16 | 14 | { |
@@ -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 | |
@@ -15,18 +15,18 @@ |
||
| 15 | 15 | public function dataTable($query) |
| 16 | 16 | { |
| 17 | 17 | return datatables($query) |
| 18 | - ->editColumn('device_id', function ($sensor) { |
|
| 19 | - return '<a href="/device/' . $sensor->device_id . '">'. $sensor->device->name . '</a>'; |
|
| 18 | + ->editColumn('device_id', function($sensor) { |
|
| 19 | + return '<a href="/device/'.$sensor->device_id.'">'.$sensor->device->name.'</a>'; |
|
| 20 | 20 | }) |
| 21 | - ->editColumn('name', function ($sensor) { |
|
| 22 | - return '<a href="/sensor/' . $sensor->id . '">'. $sensor->name . '</a>'; |
|
| 21 | + ->editColumn('name', function($sensor) { |
|
| 22 | + return '<a href="/sensor/'.$sensor->id.'">'.$sensor->name.'</a>'; |
|
| 23 | 23 | }) |
| 24 | - ->addColumn('value', function ($sensor) { |
|
| 24 | + ->addColumn('value', function($sensor) { |
|
| 25 | 25 | return $sensor->latestData->value; |
| 26 | 26 | }) |
| 27 | 27 | ->addColumn('action', 'sensor.action') |
| 28 | - ->blacklist([ 'action', 'value']) |
|
| 29 | - ->rawColumns(['device_id', 'name', 'action']); |
|
| 28 | + ->blacklist([ 'action', 'value' ]) |
|
| 29 | + ->rawColumns([ 'device_id', 'name', 'action' ]); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -9,51 +9,51 @@ discard block |
||
| 9 | 9 | class SensorController extends Controller |
| 10 | 10 | { |
| 11 | 11 | /** |
| 12 | - * Create a new controller instance. |
|
| 13 | - * |
|
| 14 | - * @return void |
|
| 15 | - */ |
|
| 12 | + * Create a new controller instance. |
|
| 13 | + * |
|
| 14 | + * @return void |
|
| 15 | + */ |
|
| 16 | 16 | public function __construct() |
| 17 | 17 | { |
| 18 | 18 | $this->middleware('auth'); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Display a listing of the resource. |
|
| 23 | - * |
|
| 24 | - * @return Response |
|
| 25 | - */ |
|
| 22 | + * Display a listing of the resource. |
|
| 23 | + * |
|
| 24 | + * @return Response |
|
| 25 | + */ |
|
| 26 | 26 | public function index(SensorDataTable $dataTable) |
| 27 | 27 | { |
| 28 | 28 | return $dataTable->render('sensor.index'); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * Show the form for creating a new resource. |
|
| 33 | - * |
|
| 34 | - * @return Response |
|
| 35 | - */ |
|
| 32 | + * Show the form for creating a new resource. |
|
| 33 | + * |
|
| 34 | + * @return Response |
|
| 35 | + */ |
|
| 36 | 36 | public function create() |
| 37 | 37 | { |
| 38 | 38 | return view('sensor.create'); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | - * Store a newly created resource in storage. |
|
| 43 | - * |
|
| 44 | - * @return Response |
|
| 45 | - */ |
|
| 42 | + * Store a newly created resource in storage. |
|
| 43 | + * |
|
| 44 | + * @return Response |
|
| 45 | + */ |
|
| 46 | 46 | public function store() |
| 47 | 47 | { |
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | - * Display the specified resource. |
|
| 53 | - * |
|
| 54 | - * @param int $id |
|
| 55 | - * @return Response |
|
| 56 | - */ |
|
| 52 | + * Display the specified resource. |
|
| 53 | + * |
|
| 54 | + * @param int $id |
|
| 55 | + * @return Response |
|
| 56 | + */ |
|
| 57 | 57 | public function show(Request $request, $id) |
| 58 | 58 | { |
| 59 | 59 | $sensor = Sensor::findOrFail($id); |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Show the form for editing the specified resource. |
|
| 66 | - * |
|
| 67 | - * @param int $id |
|
| 68 | - * @return Response |
|
| 69 | - */ |
|
| 65 | + * Show the form for editing the specified resource. |
|
| 66 | + * |
|
| 67 | + * @param int $id |
|
| 68 | + * @return Response |
|
| 69 | + */ |
|
| 70 | 70 | public function edit(Request $request, $id) |
| 71 | 71 | { |
| 72 | 72 | $sensor = Sensor::findOrFail($id); |
@@ -75,22 +75,22 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | - * Update the specified resource in storage. |
|
| 79 | - * |
|
| 80 | - * @param int $id |
|
| 81 | - * @return Response |
|
| 82 | - */ |
|
| 78 | + * Update the specified resource in storage. |
|
| 79 | + * |
|
| 80 | + * @param int $id |
|
| 81 | + * @return Response |
|
| 82 | + */ |
|
| 83 | 83 | public function update($id) |
| 84 | 84 | { |
| 85 | 85 | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | - * Remove the specified resource from storage. |
|
| 90 | - * |
|
| 91 | - * @param int $id |
|
| 92 | - * @return Response |
|
| 93 | - */ |
|
| 89 | + * Remove the specified resource from storage. |
|
| 90 | + * |
|
| 91 | + * @param int $id |
|
| 92 | + * @return Response |
|
| 93 | + */ |
|
| 94 | 94 | public function destroy($id) |
| 95 | 95 | { |
| 96 | 96 | |
@@ -9,51 +9,51 @@ discard block |
||
| 9 | 9 | class SensorDataController extends Controller |
| 10 | 10 | { |
| 11 | 11 | /** |
| 12 | - * Create a new controller instance. |
|
| 13 | - * |
|
| 14 | - * @return void |
|
| 15 | - */ |
|
| 12 | + * Create a new controller instance. |
|
| 13 | + * |
|
| 14 | + * @return void |
|
| 15 | + */ |
|
| 16 | 16 | public function __construct() |
| 17 | 17 | { |
| 18 | 18 | $this->middleware('auth'); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Display a listing of the resource. |
|
| 23 | - * |
|
| 24 | - * @return Response |
|
| 25 | - */ |
|
| 22 | + * Display a listing of the resource. |
|
| 23 | + * |
|
| 24 | + * @return Response |
|
| 25 | + */ |
|
| 26 | 26 | public function index(SensorDataDataTable $dataTable) |
| 27 | 27 | { |
| 28 | 28 | return $dataTable->render('sensordata.index'); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * Show the form for creating a new resource. |
|
| 33 | - * |
|
| 34 | - * @return Response |
|
| 35 | - */ |
|
| 32 | + * Show the form for creating a new resource. |
|
| 33 | + * |
|
| 34 | + * @return Response |
|
| 35 | + */ |
|
| 36 | 36 | public function create() |
| 37 | 37 | { |
| 38 | 38 | return view('sensordata.create'); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | - * Store a newly created resource in storage. |
|
| 43 | - * |
|
| 44 | - * @return Response |
|
| 45 | - */ |
|
| 42 | + * Store a newly created resource in storage. |
|
| 43 | + * |
|
| 44 | + * @return Response |
|
| 45 | + */ |
|
| 46 | 46 | public function store() |
| 47 | 47 | { |
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | - * Display the specified resource. |
|
| 53 | - * |
|
| 54 | - * @param int $id |
|
| 55 | - * @return Response |
|
| 56 | - */ |
|
| 52 | + * Display the specified resource. |
|
| 53 | + * |
|
| 54 | + * @param int $id |
|
| 55 | + * @return Response |
|
| 56 | + */ |
|
| 57 | 57 | public function show(Request $request, $id) |
| 58 | 58 | { |
| 59 | 59 | $sensordata = SensorData::findOrFail($id); |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Show the form for editing the specified resource. |
|
| 66 | - * |
|
| 67 | - * @param int $id |
|
| 68 | - * @return Response |
|
| 69 | - */ |
|
| 65 | + * Show the form for editing the specified resource. |
|
| 66 | + * |
|
| 67 | + * @param int $id |
|
| 68 | + * @return Response |
|
| 69 | + */ |
|
| 70 | 70 | public function edit(Request $request, $id) |
| 71 | 71 | { |
| 72 | 72 | $sensordata = SensorData::findOrFail($id); |
@@ -75,22 +75,22 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | - * Update the specified resource in storage. |
|
| 79 | - * |
|
| 80 | - * @param int $id |
|
| 81 | - * @return Response |
|
| 82 | - */ |
|
| 78 | + * Update the specified resource in storage. |
|
| 79 | + * |
|
| 80 | + * @param int $id |
|
| 81 | + * @return Response |
|
| 82 | + */ |
|
| 83 | 83 | public function update($id) |
| 84 | 84 | { |
| 85 | 85 | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | - * Remove the specified resource from storage. |
|
| 90 | - * |
|
| 91 | - * @param int $id |
|
| 92 | - * @return Response |
|
| 93 | - */ |
|
| 89 | + * Remove the specified resource from storage. |
|
| 90 | + * |
|
| 91 | + * @param int $id |
|
| 92 | + * @return Response |
|
| 93 | + */ |
|
| 94 | 94 | public function destroy($id) |
| 95 | 95 | { |
| 96 | 96 | |