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