repository = $shipping; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\B2buy\Shipping\Repositories\Criteria\ShippingResourceCriteria::class); } /** * Display a list of shipping. * * @return Response */ public function index(ShippingRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\B2buy\Shipping\Repositories\Presenter\ShippingPresenter::class) ->$function(); } $shippings = $this->repository->paginate(); return $this->response->setMetaTitle(trans('shipping::shipping.names')) ->view('shipping::shipping.index', true) ->data(compact('shippings', 'view')) ->output(); } /** * Display shipping. * * @param Request $request * @param Model $shipping * * @return Response */ public function show(ShippingRequest $request, Shipping $shipping) { if ($shipping->exists) { $view = 'shipping::shipping.show'; } else { $view = 'shipping::shipping.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('shipping::shipping.name')) ->data(compact('shipping')) ->view($view, true) ->output(); } /** * Show the form for creating a new shipping. * * @param Request $request * * @return Response */ public function create(ShippingRequest $request) { $shipping = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('shipping::shipping.name')) ->view('shipping::shipping.create', true) ->data(compact('shipping')) ->output(); } /** * Create new shipping. * * @param Request $request * * @return Response */ public function store(ShippingRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $shipping = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('shipping::shipping.name')])) ->code(204) ->status('success') ->url(guard_url('shipping/shipping/' . $shipping->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/shipping/shipping')) ->redirect(); } } /** * Show shipping for editing. * * @param Request $request * @param Model $shipping * * @return Response */ public function edit(ShippingRequest $request, Shipping $shipping) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('shipping::shipping.name')) ->view('shipping::shipping.edit', true) ->data(compact('shipping')) ->output(); } /** * Update the shipping. * * @param Request $request * @param Model $shipping * * @return Response */ public function update(ShippingRequest $request, Shipping $shipping) { try { $attributes = $request->all(); $shipping->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('shipping::shipping.name')])) ->code(204) ->status('success') ->url(guard_url('shipping/shipping/' . $shipping->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('shipping/shipping/' . $shipping->getRouteKey())) ->redirect(); } } /** * Remove the shipping. * * @param Model $shipping * * @return Response */ public function destroy(ShippingRequest $request, Shipping $shipping) { try { $shipping->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('shipping::shipping.name')])) ->code(202) ->status('success') ->url(guard_url('shipping/shipping/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('shipping/shipping/' . $shipping->getRouteKey())) ->redirect(); } } /** * Remove multiple shipping. * * @param Model $shipping * * @return Response */ public function delete(ShippingRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('shipping::shipping.name')])) ->status("success") ->code(202) ->url(guard_url('shipping/shipping')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/shipping/shipping')) ->redirect(); } } /** * Restore deleted shippings. * * @param Model $shipping * * @return Response */ public function restore(ShippingRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('shipping::shipping.name')])) ->status("success") ->code(202) ->url(guard_url('/shipping/shipping')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/shipping/shipping/')) ->redirect(); } } }