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