repository = $sitemap; parent::__construct(); } /** * Display a list of sitemap. * * @return Response */ public function index(SitemapRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('sitemap::sitemap.names').' :: '); return $this->theme->of('sitemap::admin.sitemap.index')->render(); } /** * Display a list of sitemap. * * @return Response */ public function getJson(SitemapRequest $request) { $pageLimit = $request->input('pageLimit'); $sitemaps = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Vmc\\Sitemap\\Repositories\\Presenter\\SitemapListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $sitemaps['recordsTotal'] = $sitemaps['meta']['pagination']['total']; $sitemaps['recordsFiltered'] = $sitemaps['meta']['pagination']['total']; $sitemaps['request'] = $request->all(); return response()->json($sitemaps, 200); } /** * Display sitemap. * * @param Request $request * @param Model $sitemap * * @return Response */ public function show(SitemapRequest $request, Sitemap $sitemap) { if (!$sitemap->exists) { return response()->view('sitemap::admin.sitemap.new', compact('sitemap')); } Form::populate($sitemap); return response()->view('sitemap::admin.sitemap.show', compact('sitemap')); } /** * Show the form for creating a new sitemap. * * @param Request $request * * @return Response */ public function create(SitemapRequest $request) { $sitemap = $this->repository->newInstance([]); Form::populate($sitemap); return response()->view('sitemap::admin.sitemap.create', compact('sitemap')); } /** * Create new sitemap. * * @param Request $request * * @return Response */ public function store(SitemapRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $sitemap = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('sitemap::sitemap.name')]), 'code' => 204, 'redirect' => trans_url('/admin/sitemap/sitemap/'.$sitemap->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show sitemap for editing. * * @param Request $request * @param Model $sitemap * * @return Response */ public function edit(SitemapRequest $request, Sitemap $sitemap) { Form::populate($sitemap); return response()->view('sitemap::admin.sitemap.edit', compact('sitemap')); } /** * Update the sitemap. * * @param Request $request * @param Model $sitemap * * @return Response */ public function update(SitemapRequest $request, Sitemap $sitemap) { try { $attributes = $request->all(); $sitemap->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('sitemap::sitemap.name')]), 'code' => 204, 'redirect' => trans_url('/admin/sitemap/sitemap/'.$sitemap->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/sitemap/sitemap/'.$sitemap->getRouteKey()), ], 400); } } /** * Remove the sitemap. * * @param Model $sitemap * * @return Response */ public function destroy(SitemapRequest $request, Sitemap $sitemap) { try { $t = $sitemap->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('sitemap::sitemap.name')]), 'code' => 202, 'redirect' => trans_url('/admin/sitemap/sitemap/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/sitemap/sitemap/'.$sitemap->getRouteKey()), ], 400); } } }