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