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