repository = $subject; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Course\Repositories\Criteria\SubjectResourceCriteria::class); } /** * Display a list of subject. * * @return Response */ public function index(SubjectRequest $request) { return $this->repository ->setPresenter(\Litepie\Course\Repositories\Presenter\SubjectPresenter::class) ->paginate(); } /** * Display subject. * * @param Request $request * @param Model $subject * * @return Response */ public function show(SubjectRequest $request, Subject $subject) { return $subject->setPresenter(\Litepie\Course\Repositories\Presenter\SubjectListPresenter::class); ; } /** * Create new subject. * * @param Request $request * * @return Response */ public function store(SubjectRequest $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::subject.name')]); $code = 204; $status = 'success'; $url = guard_url('course/subject/' . $subject->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/subject'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the subject. * * @param Request $request * @param Model $subject * * @return Response */ public function update(SubjectRequest $request, Subject $subject) { try { $data = $request->all(); $subject->update($data); $message = trans('messages.success.updated', ['Module' => trans('course::subject.name')]); $code = 204; $status = 'success'; $url = guard_url('course/subject/' . $subject->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/subject/' . $subject->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the subject. * * @param Model $subject * * @return Response */ public function destroy(SubjectRequest $request, Subject $subject) { try { $subject->delete(); $message = trans('messages.success.deleted', ['Module' => trans('course::subject.name')]); $code = 202; $status = 'success'; $url = guard_url('course/subject/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('course/subject/' . $subject->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); } }