fix search like in quick search and pbg data
This commit is contained in:
@@ -86,11 +86,25 @@ class RequestAssignmentController extends Controller
|
||||
// Apply search to base query
|
||||
if ($request->has('search') && !empty($request->get("search"))) {
|
||||
$search = $request->get('search');
|
||||
|
||||
// Search in pbg_task columns
|
||||
$baseQuery->where(function ($q) use ($search) {
|
||||
$q->where('name', 'LIKE', "%$search%")
|
||||
->orWhere('registration_number', 'LIKE', "%$search%")
|
||||
->orWhere('document_number', 'LIKE', "%$search%");
|
||||
->orWhere('owner_name', 'LIKE', "%$search%")
|
||||
->orWhere('address', 'LIKE', "%$search%");
|
||||
});
|
||||
|
||||
// If search term exists, also find UUIDs from name_building search
|
||||
$namesBuildingUuids = DB::table('pbg_task_details')
|
||||
->where('name_building', 'LIKE', "%$search%")
|
||||
->pluck('pbg_task_uid')
|
||||
->toArray();
|
||||
|
||||
// If we found matching name_building records, include them in the search
|
||||
if (!empty($namesBuildingUuids)) {
|
||||
$baseQuery->orWhereIn('uuid', $namesBuildingUuids);
|
||||
}
|
||||
}
|
||||
|
||||
// Get accurate count from base query (without relationships)
|
||||
@@ -98,6 +112,7 @@ class RequestAssignmentController extends Controller
|
||||
|
||||
// Clone the base query for data fetching with relationships
|
||||
$dataQuery = clone $baseQuery;
|
||||
|
||||
$dataQuery->with([
|
||||
'attachments' => function ($q) {
|
||||
$q->whereIn('pbg_type', ['berita_acara', 'bukti_bayar']);
|
||||
@@ -133,8 +148,8 @@ class RequestAssignmentController extends Controller
|
||||
// Get paginated results with relationships
|
||||
$paginatedResults = $dataQuery->paginate();
|
||||
|
||||
// Override the total count in pagination with accurate count
|
||||
$paginatedResults->withQueryString()->appends($request->query());
|
||||
// Append query parameters to pagination
|
||||
$paginatedResults->appends($request->query());
|
||||
|
||||
return RequestAssignmentResouce::collection($paginatedResults);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user