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