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