Procházet zdrojové kódy

pro-suggest - multi-term support

Vijayakrishnan před 3 roky
rodič
revize
760a4a8284
1 změnil soubory, kde provedl 17 přidání a 0 odebrání
  1. 17 0
      app/Http/Controllers/HomeController.php

+ 17 - 0
app/Http/Controllers/HomeController.php

@@ -1804,12 +1804,29 @@ WHERE measurement.label NOT IN ('SBP', 'DBP')
         $term = $request->input('term') ? trim($request->input('term')) : '';
         if (empty($term)) return '';
         $term = strtolower($term);
+
+        // if multiple words in query, check for all (max 2)
+        $term2 = '';
+        if(strpos($term, ' ') !== FALSE) {
+            $terms = explode(' ', $term);
+            $term = trim($terms[0]);
+            $term2 = trim($terms[1]);
+        }
+
         $pros = Pro::where(function ($q) use ($term) {
             $q->orWhereRaw('LOWER(name_first::text) LIKE ?', ['%' . $term . '%'])
                 ->orWhereRaw('LOWER(name_last::text) LIKE ?', ['%' . $term . '%'])
                 ->orWhereRaw('cell_number LIKE ?', ['%' . $term . '%']);
         });
 
+        if(!empty($term2)) {
+            $pros = $pros->where(function ($q) use ($term2) {
+                $q->orWhereRaw('LOWER(name_first::text) LIKE ?', ['%' . $term2 . '%'])
+                    ->orWhereRaw('LOWER(name_last::text) LIKE ?', ['%' . $term2 . '%'])
+                    ->orWhereRaw('cell_number LIKE ?', ['%' . $term2 . '%']);
+            });
+        }
+
         $type = $request->input('type') ? trim($request->input('type')) : '';
         if(!!$type) {
             switch(strtolower($type)) {