repository = $pagedata; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Pagedatum\Repositories\Criteria\PagedataResourceCriteria::class); } /** * Display a list of pagedata. * * @return Response */ public function index(PagedataRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litecms\Pagedatum\Repositories\Presenter\PagedataPresenter::class) ->$function(); } $pagedatas = $this->repository->paginate(); return $this->response->title(trans('pagedatum::pagedata.names')) ->view('pagedatum::pagedata.index', true) ->data(compact('pagedatas')) ->output(); } /** * Display pagedata. * * @param Request $request * @param Model $pagedata * * @return Response */ public function show(PagedataRequest $request, Pagedata $pagedata) { if ($pagedata->exists) { $view = 'pagedatum::pagedata.show'; } else { $view = 'pagedatum::pagedata.new'; } return $this->response->title(trans('app.view') . ' ' . trans('pagedatum::pagedata.name')) ->data(compact('pagedata')) ->view($view, true) ->output(); } /** * Show the form for creating a new pagedata. * * @param Request $request * * @return Response */ public function create(PagedataRequest $request) { $pagedata = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('pagedatum::pagedata.name')) ->view('pagedatum::pagedata.create', true) ->data(compact('pagedata')) ->output(); } /** * Create new pagedata. * * @param Request $request * * @return Response */ public function store(PagedataRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $pagedata = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('pagedatum::pagedata.name')])) ->code(204) ->status('success') ->url(guard_url('pagedatum/pagedata/' . $pagedata->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/pagedatum/pagedata')) ->redirect(); } } /** * Show pagedata for editing. * * @param Request $request * @param Model $pagedata * * @return Response */ public function edit(PagedataRequest $request, Pagedata $pagedata) { return $this->response->title(trans('app.edit') . ' ' . trans('pagedatum::pagedata.name')) ->view('pagedatum::pagedata.edit', true) ->data(compact('pagedata')) ->output(); } /** * Update the pagedata. * * @param Request $request * @param Model $pagedata * * @return Response */ public function update(PagedataRequest $request, Pagedata $pagedata) { try { $attributes = $request->all(); $pagedata->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('pagedatum::pagedata.name')])) ->code(204) ->status('success') ->url(guard_url('pagedatum/pagedata/' . $pagedata->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('pagedatum/pagedata/' . $pagedata->getRouteKey())) ->redirect(); } } /** * Remove the pagedata. * * @param Model $pagedata * * @return Response */ public function destroy(PagedataRequest $request, Pagedata $pagedata) { try { $pagedata->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('pagedatum::pagedata.name')])) ->code(202) ->status('success') ->url(guard_url('pagedatum/pagedata/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('pagedatum/pagedata/' . $pagedata->getRouteKey())) ->redirect(); } } /** * Remove multiple pagedata. * * @param Model $pagedata * * @return Response */ public function delete(PagedataRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('pagedatum::pagedata.name')])) ->status("success") ->code(202) ->url(guard_url('pagedatum/pagedata')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/pagedatum/pagedata')) ->redirect(); } } /** * Restore deleted pagedatas. * * @param Model $pagedata * * @return Response */ public function restore(PagedataRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('pagedatum::pagedata.name')])) ->status("success") ->code(202) ->url(guard_url('/pagedatum/pagedata')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/pagedatum/pagedata/')) ->redirect(); } } }