Skip to content

Commit

Permalink
fix globalsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Nov 21, 2023
1 parent 4e0a0fe commit 03b54b0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/Http/Controllers/GlobalSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ public function search(Request $request)
->where('control_user.user_id', '=', Auth::User()->id);
}

foreach ($fields as $field) {
$query->orWhere($field, 'LIKE', '%' . $term . '%');
}
$query = $query->where(function ($subQuery) use ($fields, $term) {
foreach ($fields as $field) {
if ( $field === reset( $fields ) )
$subQuery = $subQuery->where($field, 'LIKE', '%' . $term . '%');
else
$subQuery = $subQuery->orWhere($field, 'LIKE', '%' . $term . '%');
}
});

// newest first
$query->orderBy('id', 'desc');
Expand Down

0 comments on commit 03b54b0

Please sign in to comment.