Laravel – search with multiple keywords against multiple columns with the search result to be ordered in relevance

I’m not sure whether this has another method. But this is what I thought of it $word1 = ‘word1’; $word2 = ‘word2’; $word3 = ‘word3’; $all = DB::table(‘posts’) ->where(‘meta_name’, ‘like’, “%{$word1}%”) ->where(‘meta_name’, ‘like’, “%{$word2}%”) ->where(‘meta_name’, ‘like’, “%{$word3}%”) ->orWhere(function($query) use ($word1, $word2, $word3) { $query->where(‘meta_description’, ‘like’, “%{$word1}%”) ->where(‘meta_description’, ‘like’, “%{$word2}%”) ->where(‘meta_description’, ‘like’, “%{$word3}%”); }); $twoWords = … Read more