repository = $repository; $this->validator = $validator; } public function index($course_id) { $this->repository->pushCriteria(ChapterCriteria::class); $courseChapters = $this->repository->with(['course'])->where('course_id', $course_id)->get(); $chapters = $this->repository->parserResult($courseChapters); return Response::success($chapters); } public function store($course_id, Request $request) { $this->validate($request, $this->validator->getRules(ValidatorInterface::RULE_CREATE)); try { $data = $request->only(array_keys($this->validator->getRules(ValidatorInterface::RULE_CREATE))); $data['course_id'] = $course_id; $courseChapter = $this->repository->create($data); return Response::success($courseChapter); } catch (\Exception $e) { return $this->errorStore($e); } } public function show($course_id, $id) { $courseChapter = $this->repository->where('course_id', $course_id)->find($id); return Response::success($courseChapter); } public function update(Request $request, $id) { $this->validate($request, $this->validator->getRules(ValidatorInterface::RULE_UPDATE)); try { $courseChapter = $this->repository->update($request->only(array_keys($this->validator->getRules(ValidatorInterface::RULE_UPDATE))), $id); return Response::success($courseChapter); } catch (\Exception $e) { $this->errorStore($e); } } public function destroy($id) { try { $this->repository->delete($id); return Response::success(null, T('successfully delete.')); } catch (\Exception $exception) { return Response::fail(T('Delete failed.'), ResponseCodeEnum::SERVICE_UPDATE_DATA_ERROR); } } }