form = SubjectForm::setAttributes()->toArray(); $this->modules = $this->modules(config('study.course.modules'), 'course', guard_url('course')); $this->repository = $subject; } /** * Display a list of subject. * * @return Response */ public function index(SubjectRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(SubjectResourceFilter::class) ->setPresenter(SubjectListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('course::subject.names')) ->view('course::subject.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display subject. * * @param Request $request * @param Model $subject * * @return Response */ public function show(SubjectRequest $request, SubjectRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('course::subject.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('course::subject.show') ->output(); } /** * Show the form for creating a new subject. * * @param Request $request *x * @return Response */ public function create(SubjectRequest $request, SubjectRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('course::subject.name')) ->view('course::subject.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new subject. * * @param Request $request * * @return Response */ public function store(SubjectRequest $request, SubjectRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('course::subject.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('course/subject/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/course/subject')) ->redirect(); } } /** * Show subject for editing. * * @param Request $request * @param Model $subject * * @return Response */ public function edit(SubjectRequest $request, SubjectRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('course::subject.name')) ->view('course::subject.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the subject. * * @param Request $request * @param Model $subject * * @return Response */ public function update(SubjectRequest $request, SubjectRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('course::subject.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('course/subject/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('course/subject/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the subject. * * @param Model $subject * * @return Response */ public function destroy(SubjectRequest $request, SubjectRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('course::subject.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('course/subject/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('course/subject/' . $repository->getRouteKey())) ->redirect(); } } }