repository = $city; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Place\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(\Litecms\Place\Repositories\Presenter\CityPresenter::class) ->$function(); } $cities = $this->repository->paginate(); return $this->response->title(trans('place::city.names')) ->view('place::city.index', true) ->data(compact('cities')) ->output(); } /** * Display city. * * @param Request $request * @param Model $city * * @return Response */ public function show(CityRequest $request, City $city) { if ($city->exists) { $view = 'place::city.show'; } else { $view = 'place::city.new'; } return $this->response->title(trans('app.view') . ' ' . trans('place::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->title(trans('app.new') . ' ' . trans('place::city.name')) ->view('place::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('place::city.name')])) ->code(204) ->status('success') ->url(guard_url('place/city/' . $city->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/place/city')) ->redirect(); } } /** * Show city for editing. * * @param Request $request * @param Model $city * * @return Response */ public function edit(CityRequest $request, City $city) { return $this->response->title(trans('app.edit') . ' ' . trans('place::city.name')) ->view('place::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('place::city.name')])) ->code(204) ->status('success') ->url(guard_url('place/city/' . $city->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('place/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('place::city.name')])) ->code(202) ->status('success') ->url(guard_url('place/city/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('place/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('place::city.name')])) ->status("success") ->code(202) ->url(guard_url('place/city')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/place/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('place::city.name')])) ->status("success") ->code(202) ->url(guard_url('/place/city')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/place/city/')) ->redirect(); } } }