public function postUploadMeasurements(Request $request) { $input = $request->input('measurements'); try { $success = BrewingMeasurement::upload($input); } catch (BrewingMeasurementException $e) { return $this->unableToParseJsonResponse($e->getMessage()); } if ($success) { return response()->json(['message' => 'measurements_inserted_successfully']); } else { return $this->internalServerErrorJsonResponse('Unable to store measurements correctly'); } }
public function getLatestMeasurements() { $initial = BrewingMeasurement::latest(); $getResponse = function () use($initial) { $result = BrewingMeasurement::latest(); if ($result === null) { return response()->json(['measurements' => 'empty']); } else { if ($initial === null || $result->timestamp !== $initial->timestamp) { return response()->json($result); } else { return null; } } }; return $this->serveLongPolling($getResponse, response()->json(['measurements' => 'no_new_measurements'])); }