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