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