repository = $tag; } /** * Display a list of tag. * * @return Response */ public function index(TagAdminRequest $request) { $tags = $this->repository->setPresenter('\\Tag\\Tag\\Repositories\\Presenter\\TagListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('tag::tag.names').' :: '); $view = $this->theme->of('tag::admin.tag.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('tag::tag.name')]); $this->responseData = $tags['data']; $this->responseMeta = $tags['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display tag. * * @param Request $request * @param int $id * * @return Response */ public function show(TagAdminRequest $request, Tag $tag) { if (!$tag->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('tag::tag.name')]); $this->responseView = view('tag::admin.tag.new'); return $this -> respond($request); } Form::populate($tag); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('tag::tag.name')]); $this->responseData = $tag; $this->responseView = view('tag::admin.tag.show', compact('tag')); return $this -> respond($request); } /** * Show the form for creating a new tag. * * @param Request $request * * @return Response */ public function create(TagAdminRequest $request) { $tag = $this->repository->newInstance([]); Form::populate($tag); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('tag::tag.name')]); $this->responseData = $tag; $this->responseView = view('tag::admin.tag.create', compact('tag')); return $this -> respond($request); } /** * Create new tag. * * @param Request $request * * @return Response */ public function store(TagAdminRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $tag = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('tag::tag.name')]); $this->responseData = $tag; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/tag/tag/'.$tag->getRouteKey()); $this->responseView = view('tag::admin.tag.create', compact('tag')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show tag for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(TagAdminRequest $request, Tag $tag) { Form::populate($tag); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('tag::tag.name')]); $this->responseData = $tag; $this->responseView = view('tag::admin.tag.edit', compact('tag')); return $this -> respond($request); } /** * Update the tag. * * @param Request $request * @param int $id * * @return Response */ public function update(TagAdminRequest $request, Tag $tag) { try { $attributes = $request->all(); $tag->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('tag::tag.name')]); $this->responseData = $tag; $this->responseRedirect = trans_url('/admin/tag/tag/'.$tag->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/tag/tag/'.$tag->getRouteKey()); return $this -> respond($request); } } /** * Remove the tag. * * @param int $id * * @return Response */ public function destroy(TagAdminRequest $request, Tag $tag) { try { $t = $tag->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('tag::tag.name')]); $this->responseRedirect = trans_url('/admin/tag/tag/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/tag/tag/'.$tag->getRouteKey()); return $this -> respond($request); } } }