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