model = new CounterModel(); } public function index() { $rows = $this->model->findAll(); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "No Data.", 'data' => [] ], 200); } return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200); } public function show($CounterID = null) { $row = $this->model->find($CounterID); if (empty($row)) { return $this->respond([ 'status' => 'success', 'message' => "No Data.", 'data' => null ], 200); } return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row ], 200); } public function create() { $input = $this->request->getJSON(true); try { $id = $this->model->insert($input,true); return $this->respondCreated([ 'status' => 'success', 'message' => 'Data created successfully', 'data' => $id ], 201); } catch (\Throwable $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } } public function update() { $input = $this->request->getJSON(true); try { $this->model->update($input['CounterID'], $input); return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', 'data' => $input['CounterID'] ], 201); } catch (\Throwable $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } } public function delete() { $input = $this->request->getJSON(true); try { $this->model->delete($input['CounterID'], $input); return $this->respondCreated([ 'status' => 'success', 'message' => 'Data deleted successfully', 'data' => $input['CounterID'] ], 201); } catch (\Throwable $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } } }