Laravel查询生成器搜索(匹配)

时间:2016-07-20 19:08:32

标签: php mysql laravel

我正在尝试在Laravel中编写此查询

select *, MATCH(hobbies)AGAINST('soccer') from users where MATCH(hobbies)AGAINST('soccer' IN BOOLEAN MODE) LIMIT 10 OFFSET 0;

我查看了有关查询构建器的文档但在全文搜索中找不到任何内容。

请帮忙。

提前谢谢你:)

2 个答案:

答案 0 :(得分:5)

User::selectRaw("*, MATCH(hobbies)AGAINST('soccer')")
    ->whereRaw("MATCH(hobbies)AGAINST('soccer' IN BOOLEAN MODE)")
    ->limit(10);

答案 1 :(得分:3)

感谢Samsquanch,他指出了我正确的方向。 这就是我完成它的方式。

$my_query = "select *, MATCH (name) AGAINST (?) from users 
    where MATCH (hobbies) AGAINST (? IN BOOLEAN MODE) limit 10 OFFSET ?"

$hobbies = DB::select($my_query, array($search_term, $search_term, (($page-1)*10)));