laravel搜索多个按空格分隔的单词
2022-08-30 19:32:21
我是laravel查询构建器的新手,我想搜索在输入字段中输入的多个单词,例如,如果我键入“jhon doe”,我想获取任何包含jhon或doe的列
我已经看到/尝试过使用php MySQL的解决方案,但无法适应查询构建器
//1. exploding the space between the keywords
//2. using foreach apend the query together
$query = "select * from users where";
$keywordRaw = "jhon doe";
$keywords = explode(' ', $keywordRaw );
foreach ($keywords as $keyword){
$query.= " first_name LIKE '%" + $keyword +"%' OR ";
}
如何使用查询生成器执行此操作
这就是我到目前为止所拥有的,什么是正确的方法来做到这一点,
$keywordRaw = "jhon doe";
//how do I explode this words and append them along with their appropriate query
$users = User::select('users.*')
->where('first_name', 'LIKE', '%'.$keywordRaw.'%')
请帮忙,提前致谢