如何在laravel 5.2中找到给定输入的常用词?

时间:2017-05-15 17:26:55

标签: php sql laravel laravel-5.2

我在这里陷入困境。这是我的问题: - 我有一个表服务

 maxList = max(newList)
 return newList.index(maxList), maxList

现在我有一个输入是: -

Service table
id     searchservice
1        waxing
2        Waxing
3        American Service
4        Waxing

现在我想找到所有带有打蜡文本的记录,即我想要获取ID 1,2,4

 $searchKeyword = Indian waxing

它给了我空洞的结果。我知道在这里我必须使用另一个sql函数。任何人都可以帮助我提前谢谢:)。我正在使用laravel 5.2框架

1 个答案:

答案 0 :(得分:1)

您正在寻找"印度打蜡"如果你想单独搜索每个单词,你必须这样做:

$searchKeyword = "Indian waxing"
$keywords = explode(" ", $searchKeyword);

$service = Service::query();
foreach($keywords as $word){
    $service->orWhere('searchservice', 'LIKE', '%'.$word.'%');
}

$services = $service->distinct()->get();