repository = $topic; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Cenos\Master\Repositories\Criteria\TopicResourceCriteria::class); } /** * Display a list of topic. * * @return Response */ public function index(TopicRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Cenos\Master\Repositories\Presenter\TopicPresenter::class) ->$function(); } $topics = $this->repository->paginate(); return $this->response->setMetaTitle(trans('master::topic.names')) ->view('master::topic.index', true) ->data(compact('topics', 'view')) ->output(); } /** * Display topic. * * @param Request $request * @param Model $topic * * @return Response */ public function show(TopicRequest $request, Topic $topic) { if ($topic->exists) { $view = 'master::topic.show'; } else { $view = 'master::topic.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('master::topic.name')) ->data(compact('topic')) ->view($view, true) ->output(); } /** * Show the form for creating a new topic. * * @param Request $request * * @return Response */ public function create(TopicRequest $request) { $topic = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('master::topic.name')) ->view('master::topic.create', true) ->data(compact('topic')) ->output(); } /** * Create new topic. * * @param Request $request * * @return Response */ public function store(TopicRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $topic = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('master::topic.name')])) ->code(204) ->status('success') ->url(guard_url('master/topic/' . $topic->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/master/topic')) ->redirect(); } } /** * Show topic for editing. * * @param Request $request * @param Model $topic * * @return Response */ public function edit(TopicRequest $request, Topic $topic) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('master::topic.name')) ->view('master::topic.edit', true) ->data(compact('topic')) ->output(); } /** * Update the topic. * * @param Request $request * @param Model $topic * * @return Response */ public function update(TopicRequest $request, Topic $topic) { try { $attributes = $request->all(); $topic->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('master::topic.name')])) ->code(204) ->status('success') ->url(guard_url('master/topic/' . $topic->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('master/topic/' . $topic->getRouteKey())) ->redirect(); } } /** * Remove the topic. * * @param Model $topic * * @return Response */ public function destroy(TopicRequest $request, Topic $topic) { try { $topic->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('master::topic.name')])) ->code(202) ->status('success') ->url(guard_url('master/topic/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('master/topic/' . $topic->getRouteKey())) ->redirect(); } } /** * Remove multiple topic. * * @param Model $topic * * @return Response */ public function delete(TopicRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('master::topic.name')])) ->status("success") ->code(202) ->url(guard_url('master/topic')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/master/topic')) ->redirect(); } } /** * Restore deleted topics. * * @param Model $topic * * @return Response */ public function restore(TopicRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('master::topic.name')])) ->status("success") ->code(202) ->url(guard_url('/master/topic')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/master/topic/')) ->redirect(); } } }