diff --git a/src/Entities/District.php b/src/Entities/District.php index 4b34d15..ddcc1f8 100644 --- a/src/Entities/District.php +++ b/src/Entities/District.php @@ -75,7 +75,7 @@ public function getDistrictsWithMunicipalities() public function getDistrictsByProvince($provinceId) { return array_values(array_filter($this->items, function ($item) use ($provinceId) { - return ($item->province_id == $provinceId); + return property_exists($item, 'province_id') && ($item->province_id == $provinceId); })); } diff --git a/src/Entities/Municipality.php b/src/Entities/Municipality.php index cff2102..c00b8ad 100644 --- a/src/Entities/Municipality.php +++ b/src/Entities/Municipality.php @@ -59,7 +59,7 @@ public function allMunicipalities() public function getMunicipalitiesByDistrict($districtId) { return array_values(array_filter($this->items, function ($item) use ($districtId) { - return ($item->district_id == $districtId); + return property_exists($item, 'district_id') && ($item->district_id == $districtId); })); } @@ -72,7 +72,7 @@ public function getMunicipalitiesByDistrict($districtId) public function getMunicipalityByCategory($categoryId) { return array_values(array_filter($this->items, function ($item) use ($categoryId) { - return ($item->category_id == $categoryId); + return property_exists($item, 'category_id') && ($item->category_id == $categoryId); })); } @@ -87,7 +87,7 @@ public function getMunicipalityByProvince($provinceId) $district = new District(); $districts = $district->getDistrictsByProvince($provinceId); $municipalities = array_map(function ($item) { - return $this->getMunicipalitiesByDistrict($item->id); + return $this->getMunicipalitiesByDistrict($item->id ?? 0); }, $districts); return array_merge(...$municipalities); @@ -154,14 +154,14 @@ public function wards($id) if($this->lang == 'np'){ - $totalWards = Helper::numericEnglish($municipality->wards); + $totalWards = Helper::numericEnglish($municipality->wards ?? 1); $wards = range(1, $totalWards); $wards = array_map(function ($item){ return Helper::numericNepali($item); }, $wards); }else{ - $wards = range(1, $municipality->wards); + $wards = range(1, $municipality->wards ?? 1); } return $wards; }