form = NewsForm::setAttributes()->toArray(); $this->modules = $this->modules(config('newgenpower.news.modules'), 'news', guard_url('news')); $this->repository = $news; } /** * Display a list of news. * * @return Response */ public function index(NewsRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(NewsResourceFilter::class) ->setPresenter(NewsListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('news::news.names')) ->view('news::news.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display news. * * @param Request $request * @param Model $news * * @return Response */ public function show(NewsRequest $request, NewsRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('news::news.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('news::news.show') ->output(); } /** * Show the form for creating a new news. * * @param Request $request *x * @return Response */ public function create(NewsRequest $request, NewsRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('news::news.name')) ->view('news::news.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new news. * * @param Request $request * * @return Response */ public function store(NewsRequest $request, NewsRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('news::news.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('news/news/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/news/news')) ->redirect(); } } /** * Show news for editing. * * @param Request $request * @param Model $news * * @return Response */ public function edit(NewsRequest $request, NewsRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('news::news.name')) ->view('news::news.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the news. * * @param Request $request * @param Model $news * * @return Response */ public function update(NewsRequest $request, NewsRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('news::news.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('news/news/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('news/news/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the news. * * @param Model $news * * @return Response */ public function destroy(NewsRequest $request, NewsRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('news::news.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('news/news/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('news/news/' . $repository->getRouteKey())) ->redirect(); } } }