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