Jelajahi Sumber

add whereOr('word_en

visuddhinanda 3 tahun lalu
induk
melakukan
fe119111a7
1 mengubah file dengan 4 tambahan dan 6 penghapusan
  1. 4 6
      app/Http/Controllers/VocabularyController.php

+ 4 - 6
app/Http/Controllers/VocabularyController.php

@@ -21,13 +21,11 @@ class VocabularyController extends Controller
             case 'key':
                 $key = $request->get("key");
                 $result = Cache::remember("/dict_vocabulary/{$key}",60,function() use($key){
-                    return Vocabulary::where('word_en','like',$key."%")->take(10)->get();
+                    return Vocabulary::where('word','like',$key."%")
+                                    ->whereOr('word_en','like',$key."%")
+                                    ->take(10)->get();
                 });
-                if($result){
-                    return $this->ok(['rows'=>VocabularyResource::collection($result),'count'=>count($result)]);
-                }else{
-                    return $this->error();
-                }
+                return $this->ok(['rows'=>VocabularyResource::collection($result),'count'=>count($result)]);
                 break;
         }
     }