repository = $tag; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Survey\Question\Repositories\Criteria\TagResourceCriteria::class); } /** * Display a list of tag. * * @return Response */ public function index(TagRequest $request) { return $this->repository ->setPresenter(\Survey\Question\Repositories\Presenter\TagPresenter::class) ->paginate(); } /** * Display tag. * * @param Request $request * @param Model $tag * * @return Response */ public function show(TagRequest $request, Tag $tag) { return $tag->setPresenter(\Survey\Question\Repositories\Presenter\TagListPresenter::class); ; } /** * Create new tag. * * @param Request $request * * @return Response */ public function store(TagRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('question::tag.name')]); $code = 204; $status = 'success'; $url = guard_url('question/tag/' . $tag->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('question/tag'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the tag. * * @param Request $request * @param Model $tag * * @return Response */ public function update(TagRequest $request, Tag $tag) { try { $data = $request->all(); $tag->update($data); $message = trans('messages.success.updated', ['Module' => trans('question::tag.name')]); $code = 204; $status = 'success'; $url = guard_url('question/tag/' . $tag->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('question/tag/' . $tag->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the tag. * * @param Model $tag * * @return Response */ public function destroy(TagRequest $request, Tag $tag) { try { $tag->delete(); $message = trans('messages.success.deleted', ['Module' => trans('question::tag.name')]); $code = 202; $status = 'success'; $url = guard_url('question/tag/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('question/tag/' . $tag->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }