ソースを参照

Merge branch 'master' into dev-vj

Vijayakrishnan 3 年 前
コミット
9095ca9abc
1 ファイル変更12 行追加6 行削除
  1. 12 6
      app/Http/Controllers/HomeController.php

+ 12 - 6
app/Http/Controllers/HomeController.php

@@ -775,6 +775,7 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
 
         $pro = $this->pro;
         $term = $request->input('term') ? trim($request->input('term')) : '';
+        $originalTerm = $term;
         if (empty($term)) return '';
 
         // if multiple words in query, check for all (max 2)
@@ -785,20 +786,25 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
             $term2 = trim($terms[1]);
         }
 
+        $phoneNumberTerm = preg_replace("/[^0-9]/", "", $originalTerm );
+        if($phoneNumberTerm == ""){  //to avoid search with blank string
+            $phoneNumberTerm = $term;
+        }
+
         $clientQuery= Client::whereNull('shadow_pro_id')
-            ->where(function ($q) use ($term) {
+            ->where(function ($q) use ($term, $phoneNumberTerm) {
                 $q->where('name_first', 'ILIKE', '%' . $term . '%')
                     ->orWhere('name_last', 'ILIKE', '%' . $term . '%')
-                    ->orWhere('cell_number', 'ILIKE', '%' . $term . '%')
-                    ->orWhere('phone_home', 'ILIKE', '%' . $term . '%');
+                    ->orWhere('cell_number', 'ILIKE', '%' . $phoneNumberTerm . '%')
+                    ->orWhere('phone_home', 'ILIKE', '%' . $phoneNumberTerm . '%');
             });
 
         if(!empty($term2)) {
-            $clientQuery = $clientQuery->where(function ($q) use ($term2) {
+            $clientQuery = $clientQuery->where(function ($q) use ($term2, $phoneNumberTerm) {
                 $q->where('name_first', 'ILIKE', '%' . $term2 . '%')
                     ->orWhere('name_last', 'ILIKE', '%' . $term2 . '%')
-                    ->orWhere('cell_number', 'ILIKE', '%' . $term2 . '%')
-                    ->orWhere('phone_home', 'ILIKE', '%' . $term2 . '%');
+                    ->orWhere('cell_number', 'ILIKE', '%' . $phoneNumberTerm . '%')
+                    ->orWhere('phone_home', 'ILIKE', '%' . $phoneNumberTerm . '%');
             });
         }