repository = $catalogo; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(CatalogoUserWebRequest $request) { $this->repository->pushCriteria(new \Lavalite\Catalogo\Repositories\Criteria\CatalogoUserCriteria()); $catalogos = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('catalogo::catalogo.names').' :: '); return $this->theme->of('catalogo::user.catalogo.index', compact('catalogos'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Catalogo $catalogo * * @return Response */ public function show(CatalogoUserWebRequest $request, Catalogo $catalogo) { Form::populate($catalogo); return $this->theme->of('catalogo::user.catalogo.show', compact('catalogo'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(CatalogoUserWebRequest $request) { $catalogo = $this->repository->newInstance([]); Form::populate($catalogo); return $this->theme->of('catalogo::user.catalogo.create', compact('catalogo'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(CatalogoUserWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $catalogo = $this->repository->create($attributes); return redirect(trans_url('/user/catalogo/catalogo')) -> with('message', trans('messages.success.created', ['Module' => trans('catalogo::catalogo.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Catalogo $catalogo * * @return Response */ public function edit(CatalogoUserWebRequest $request, Catalogo $catalogo) { Form::populate($catalogo); return $this->theme->of('catalogo::user.catalogo.edit', compact('catalogo'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Catalogo $catalogo * * @return Response */ public function update(CatalogoUserWebRequest $request, Catalogo $catalogo) { try { $this->repository->update($request->all(), $catalogo->getRouteKey()); return redirect(trans_url('/user/catalogo/catalogo')) ->with('message', trans('messages.success.updated', ['Module' => trans('catalogo::catalogo.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(CatalogoUserWebRequest $request, Catalogo $catalogo) { try { $this->repository->delete($catalogo->getRouteKey()); return redirect(trans_url('/user/catalogo/catalogo')) ->with('message', trans('messages.success.deleted', ['Module' => trans('catalogo::catalogo.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }