如何检索 laravel 5.2 行中的常用词

how to retrieve the common words in rows in laravel 5.2

我卡在这上面了。我有两个复选框,即修指甲和修脚 当用户 select 美甲 ajax 运行时,然后我想从所有行中找到美甲字样:-

enter code here
id   name
 1    Get Manicure
 2    Manicure & Pedicure
 3    Repair Manicure
 4    Get Pedicure
 5    Dummy text

现在假设我的 table 中有五个记录 当用户点击 修指甲 复选框时,我希望它必须 returns 1,2,3 id 当用户点击修指甲和修脚时,我想要 1,2,3,4 记录 当用户点击修脚时,只有 2,4 id 必须 return 谁能帮我实现这个 functionality.Here 是我的代码

enter code here
$query = Service::whereIn('name',array('Pedicure'))->get();// Only pedicure
$query = Service::whereIn('name',array('Manicure'))->get(); // Only manicure
$query = Service::whereIn('name',array('Manicure','pedicure'))->get(); //Both

我认为它可能与 where 条件一起工作,中间有 forloop

像这样更改您的查询

//$searchArray = ['Manicure'];
//$searchArray = ['pedicure'];
$searchArray = ['Manicure','pedicure'];
$query = new Service();
$isFirst = true;
foreach($searchArray as $string){
    if($isFirst){
        $query->where('name','like','%'.$string.'%');
        $isFirst = false;
    }else{
        $query->orWhere('name','like','%'.$string.'%');
    }
}
$result = $query->get();