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