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