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