repository = $vote_topic; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Newage\Votes\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\Votes\Repositories\Presenter\VoteTopicPresenter::class) ->$function(); } $vote_topics = $this->repository->paginate(); return $this->response->title(trans('votes::vote_topic.names')) ->view('votes::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 = 'votes::vote_topic.show'; } else { $view = 'votes::vote_topic.new'; } return $this->response->title(trans('app.view') . ' ' . trans('votes::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('votes::vote_topic.name')) ->view('votes::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('votes::vote_topic.name')])) ->code(204) ->status('success') ->url(guard_url('votes/vote_topic/' . $vote_topic->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/votes/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('votes::vote_topic.name')) ->view('votes::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('votes::vote_topic.name')])) ->code(204) ->status('success') ->url(guard_url('votes/vote_topic/' . $vote_topic->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('votes/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('votes::vote_topic.name')])) ->code(202) ->status('success') ->url(guard_url('votes/vote_topic/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('votes/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('votes::vote_topic.name')])) ->status("success") ->code(202) ->url(guard_url('votes/vote_topic')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/votes/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('votes::vote_topic.name')])) ->status("success") ->code(202) ->url(guard_url('/votes/vote_topic')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/votes/vote_topic/')) ->redirect(); } } }