【发布时间】:2015-03-31 22:57:32
【问题描述】:
我是 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.'%')
请帮忙,提前谢谢
【问题讨论】:
标签: php mysql laravel eloquent query-builder