country_model = $countryModel; $this->city_model = $cityModel; $this->district_model = $districtModel; $this->neighborhood_model = $neighborhoodModel; $this->village_model = $villageModel; parent::__construct(); } /** * @return mixed */ public function getCountries() { if ($this->request->id) return $this->country_model->find($this->request->id); else return $this->country_model->orderBy('order', 'ASC')->get(); } /** * @return mixed */ public function getCities() { if ($this->request->id) { $id = explode(',', $this->request->id); return $this->city_model->whereIn('parent_country_id', $id)->orderBy('order', 'ASC')->get(); } } /** * @return mixed */ public function getDistricts() { if ($this->request->id) { $id = explode(',', $this->request->id); return $this->district_model->whereIn('parent_city_id', $id)->orderBy('order', 'ASC')->get(); } } /** * @return mixed */ public function getNeighborhoods() { if ($this->request->id) { $id = explode(',', $this->request->id); return $this->neighborhood_model->whereIn('parent_district_id', $id)->orderBy('order', 'ASC')->get(); } } /** * @return mixed */ public function getVillage() { if ($this->request->id) { $id = explode(',', $this->request->id); return $this->village_model->whereIn('parent_neighborhood_id', $id)->orderBy('order', 'ASC')->get(); } } /** * @return mixed */ public function getCity() { if ($this->request->name) { $slug = Str::slug($this->request->name, '_'); if ($city = $this->city_model->newQuery()->where('slug', 'LIKE', $slug . '%')->first()) { return ['success' => true, 'link' => route('visiosoft.module.advs::list') . '?city[]=' . $city->id]; } else { return ['success' => false]; } } } }