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