如何从 laravel 5.2 中的给定输入中找到常用词?
how to find the common word from given input in laravel 5.2?
我在这里陷入困境。这是我的问题:-
我有一个 table 服务
Service table
id searchservice
1 waxing
2 Waxing
3 American Service
4 Waxing
现在我有一个输入是:-
$searchKeyword = Indian waxing
现在我想找到所有带有打蜡文本的记录,即我想获取 ID 1、2、4
enter code here
Service::Where('searchservice','like','%'.$searchKeyword.'%')->get();
它给了我空的结果。我知道我必须使用另一个 sql 函数。任何人都可以帮我提前谢谢 :) 。我正在使用 laravel 5.2 框架
您正在搜索 "Indian waxing" 如果您想单独搜索每个单词,则必须执行以下操作:
$searchKeyword = "Indian waxing"
$keywords = explode(" ", $searchKeyword);
$service = Service::query();
foreach($keywords as $word){
$service->orWhere('searchservice', 'LIKE', '%'.$word.'%');
}
$services = $service->distinct()->get();
我在这里陷入困境。这是我的问题:- 我有一个 table 服务
Service table
id searchservice
1 waxing
2 Waxing
3 American Service
4 Waxing
现在我有一个输入是:-
$searchKeyword = Indian waxing
现在我想找到所有带有打蜡文本的记录,即我想获取 ID 1、2、4
enter code here
Service::Where('searchservice','like','%'.$searchKeyword.'%')->get();
它给了我空的结果。我知道我必须使用另一个 sql 函数。任何人都可以帮我提前谢谢 :) 。我正在使用 laravel 5.2 框架
您正在搜索 "Indian waxing" 如果您想单独搜索每个单词,则必须执行以下操作:
$searchKeyword = "Indian waxing"
$keywords = explode(" ", $searchKeyword);
$service = Service::query();
foreach($keywords as $word){
$service->orWhere('searchservice', 'LIKE', '%'.$word.'%');
}
$services = $service->distinct()->get();