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