Feature #5 : Activate Filter Button on Table on Each Module Location

This commit is contained in:
Daeng Deni Mardaeni
2024-08-10 20:13:04 +07:00
parent d73a006ce0
commit ae1a6c6513
8 changed files with 107 additions and 142 deletions

View File

@@ -16,7 +16,8 @@ class DistrictsController extends Controller
public $user;
public function index(){
return view('location::districts.index');
$provinces = Province::all();
return view('location::districts.index', compact('provinces'));
}
public function create(){
@@ -78,11 +79,16 @@ class DistrictsController extends Controller
// Apply search filter if provided
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[1]) &&!empty($search[1])){
$query->where('city_code',$search[1]);
}
$query->where(function ($q) use ($search) {
$q->where('code', 'LIKE', "%$search%");
$q->orWhere('name', 'LIKE', "%$search%");
$q->orWhereRelation('city','name', 'LIKE', "%$search%");
$q->orWhereRelation('city.province','name', 'LIKE', "%$search%");
$q->where('code', 'LIKE', "%$search[2]%");
$q->orWhere('name', 'LIKE', "%$search[2]%");
});
}
@@ -109,7 +115,7 @@ class DistrictsController extends Controller
$filteredRecords = $query->count();
// Get the data for the current page
$cities = $query->with('city.province')->get();
$data = $query->with('city.province')->get();
// Calculate the page count
$pageCount = ceil($totalRecords/$request->get('size'));
@@ -125,7 +131,7 @@ class DistrictsController extends Controller
'pageCount' => $pageCount,
'page' => $currentPage,
'totalCount' => $totalRecords,
'data' => $cities,
'data' => $data,
]);
}