repository = $course; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Course\Repositories\Criteria\CourseResourceCriteria::class); } /** * Display a list of course. * * @return Response */ public function index(CourseRequest $request) { return $this->repository ->setPresenter(\Litepie\Course\Repositories\Presenter\CoursePresenter::class) ->paginate(); } /** * Display course. * * @param Request $request * @param Model $course * * @return Response */ public function show(CourseRequest $request, Course $course) { return $course->setPresenter(\Litepie\Course\Repositories\Presenter\CourseListPresenter::class); ; } /** * Create new course. * * @param Request $request * * @return Response */ public function store(CourseRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('course::course.name')]); $code = 204; $status = 'success'; $url = guard_url('course/course/' . $course->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/course'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the course. * * @param Request $request * @param Model $course * * @return Response */ public function update(CourseRequest $request, Course $course) { try { $data = $request->all(); $course->update($data); $message = trans('messages.success.updated', ['Module' => trans('course::course.name')]); $code = 204; $status = 'success'; $url = guard_url('course/course/' . $course->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/course/' . $course->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the course. * * @param Model $course * * @return Response */ public function destroy(CourseRequest $request, Course $course) { try { $course->delete(); $message = trans('messages.success.deleted', ['Module' => trans('course::course.name')]); $code = 202; $status = 'success'; $url = guard_url('course/course/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/course/' . $course->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }