repository = $course; parent::__construct(); } /** * Display a list of course. * * @return json */ public function index(CourseRequest $request) { $courses = $this->repository ->setPresenter('\\Dipendra\\Programming\\Repositories\\Presenter\\CourseListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $courses['code'] = 2000; return response()->json($courses) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display course. * * @param Request $request * @param Model Course * * @return Json */ public function show(CourseRequest $request, Course $course) { $course = $course->presenter(); $course['code'] = 2001; return response()->json($course) ->setStatusCode(200, 'SHOW_SUCCESS');; } /** * Show the form for creating a new course. * * @param Request $request * * @return json */ public function create(CourseRequest $request, Course $course) { $course = $course->presenter(); $course['code'] = 2002; return response()->json($course) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new course. * * @param Request $request * * @return json */ public function store(CourseRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $course = $this->repository->create($attributes); $course = $course->presenter(); $course['code'] = 2004; return response()->json($course) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show course for editing. * * @param Request $request * @param Model $course * * @return json */ public function edit(CourseRequest $request, Course $course) { $course = $course->presenter(); $course['code'] = 2003; return response()-> json($course) ->setStatusCode(200, 'EDIT_SUCCESS');; } /** * Update the course. * * @param Request $request * @param Model $course * * @return json */ public function update(CourseRequest $request, Course $course) { try { $attributes = $request->all(); $course->update($attributes); $course = $course->presenter(); $course['code'] = 2005; return response()->json($course) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the course. * * @param Request $request * @param Model $course * * @return json */ public function destroy(CourseRequest $request, Course $course) { try { $t = $course->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('programming::course.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }