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