From 03b54b06fec3f1c790b17b53c67fc34b5446c43b Mon Sep 17 00:00:00 2001 From: Didier Date: Tue, 21 Nov 2023 15:45:38 +0100 Subject: [PATCH] fix globalsearch --- app/Http/Controllers/GlobalSearchController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/GlobalSearchController.php b/app/Http/Controllers/GlobalSearchController.php index 3c87369b..18d0d3cd 100644 --- a/app/Http/Controllers/GlobalSearchController.php +++ b/app/Http/Controllers/GlobalSearchController.php @@ -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');