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