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

@@ -17,7 +17,8 @@ class CitiesController extends Controller
public $user;
public function index(){
return view('location::cities.index');
$provinces = Province::all();
return view('location::cities.index', compact('provinces'));
}
public function create(){
@@ -78,10 +79,14 @@ class CitiesController 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]);
}
$query->where(function ($q) use ($search) {
$q->where('code', 'LIKE', "%$search%");
$q->orWhere('name', 'LIKE', "%$search%");
$q->orWhereRelation('province','name', 'LIKE', "%$search%");
$q->where('code', 'LIKE', "%$search[1]%");
$q->orWhere('name', 'LIKE', "%$search[1]%");
$q->orWhereRelation('province','name', 'LIKE', "%$search[1]%");
});
}
@@ -108,7 +113,7 @@ class CitiesController extends Controller
$filteredRecords = $query->count();
// Get the data for the current page
$cities = $query->with('province')->get();
$data = $query->with('province')->get();
// Calculate the page count
$pageCount = ceil($totalRecords/$request->get('size'));
@@ -124,7 +129,7 @@ class CitiesController extends Controller
'pageCount' => $pageCount,
'page' => $currentPage,
'totalCount' => $totalRecords,
'data' => $cities,
'data' => $data,
]);
}