diff --git a/app/Http/Controllers/VillagesController.php b/app/Http/Controllers/VillagesController.php index 88726f1..7f6dcdf 100644 --- a/app/Http/Controllers/VillagesController.php +++ b/app/Http/Controllers/VillagesController.php @@ -99,8 +99,21 @@ if ($request->has('search') && !empty($request->get('search'))) { $search = $request->get('search'); $search = explode('|', $search); - if(isset($search[0]) &&!empty($search[0])){ - $query->where('province_code',$search[0]); + if(isset($search[0]) && !empty($search[0])){ + // Define special city codes once + $specialCityCodes = ['92.01', '92.04', '92.05', '92.09', '92.10', '92.71']; + + // Handle Papua province special cases + if($search[0] == '92'){ + $query->where('province_code', '92') + ->whereNotIn('city_code', $specialCityCodes); + } else if($search[0] == '92.1'){ + $query->where('province_code', '92') + ->whereIn('city_code', $specialCityCodes); + } else { + // For all other provinces + $query->where('province_code', $search[0]); + } } if(isset($search[1]) &&!empty($search[1])){ $query->where('city_code',$search[1]); @@ -146,6 +159,15 @@ // Calculate the current page number $currentPage = 0 + 1; + $data = $data->map(function ($item) { + if (in_array($item->city_code, ['92.01', '92.04', '92.05', '92.09', '92.10', '92.71'])) { + $item->province_name = Province::where('code', '92.1')->first()->name; + } else { + $item->province_name = $item->district->city->province->name; + } + return $item; + }); + // Return the response data as a JSON object return response()->json([ 'draw' => $request->get('draw'), diff --git a/app/Http/Requests/VillageRequest.php b/app/Http/Requests/VillageRequest.php index c3b33fe..5c7cee7 100644 --- a/app/Http/Requests/VillageRequest.php +++ b/app/Http/Requests/VillageRequest.php @@ -21,10 +21,10 @@ ]; if ($this->method() === 'PUT') { - $rules['code'] = 'required|string|max:6|unique:villages,code,' . $this->id; + $rules['code'] = 'required|string|max:13|unique:villages,code,' . $this->id; $rules['name'] = 'required|string|max:2554|unique:villages,name,' . $this->id; } else { - $rules['code'] = 'required|string|max:6|unique:villages,code'; + $rules['code'] = 'required|string|max:13|unique:villages,code'; $rules['name'] = 'required|string|max:2554|unique:villages,name'; } diff --git a/resources/views/villages/index.blade.php b/resources/views/villages/index.blade.php index 2188334..60c3ff2 100644 --- a/resources/views/villages/index.blade.php +++ b/resources/views/villages/index.blade.php @@ -47,9 +47,8 @@ -
+ Export to Excel Add District @@ -192,7 +191,7 @@ province: { title: 'Province', render: (item, data) => { - return data.district.city.province.name; + return data.province_name; } }, actions: {