getQueryParams(); $benchmark = Benchmark::where('id', $urlParams['benchmark_id'])->first(); $payload = json_encode($benchmark); $response->getBody()->write($payload); return $response ->withHeader('Content-Type', 'application/json'); } public function getBenchmarkTests(Request $request, Response $response, array $args): Response { $urlParams = $request->getQueryParams(); $benchmark = Benchmark::where('id', $urlParams['benchmark_id'])->first(); $payload = json_encode($benchmark->tests); $response->getBody()->write($payload); return $response ->withHeader('Content-Type', 'application/json'); } public function getResultList(Request $request, Response $response, array $args): Response { $urlParams = $request->getQueryParams(); $results = Result::where([ ['benchmark_id', '=', $urlParams['benchmark_id']], ['test_id', '=', $urlParams['test_id']], ])->get(); $payload = json_encode($results); $response->getBody()->write($payload); return $response ->withHeader('Content-Type', 'application/json'); } public function postResultAdd(Request $request, Response $response, array $args): Response { $params = (array)$request->getParsedBody(); $result = new Result; $result->test_id = $params['result_test']; $result->benchmark_id = $params['result_benchmark']; $result->average = $params['result_avg']; $result->minimum = $params['result_min'] ?? null; $result->maximum = $params['result_max'] ?? null; $result->save(); $payload = json_encode('success'); $response->getBody()->write($payload); return $response ->withHeader('Content-Type', 'application/json'); } public function getTestDetails(Request $request, Response $response, array $args): Response { $urlParams = $request->getQueryParams(); $test = Test::where('id', $urlParams['test_id'])->first(); $payload = json_encode($test); $response->getBody()->write($payload); return $response ->withHeader('Content-Type', 'application/json'); } }