我已经尝试了很多方法,但我的知识还不够好XD
DB::select ('SELECT c.`id_client`, UPPER (c.`name`) AS `name`, '
. 'c.`telephone`, MATCH (c.`name`) AGAINST ( ? ) AS `match` '
. 'FROM client c '
. 'WHERE MATCH (c.`name`) AGAINST ( ? ) '
. 'HAVING `match` > 5.2 ORDER BY `match` DESC LIMIT 10', array ($name, $name));
最佳答案
不确定是否可以用 Eloquent 来完成,也许 Fluent相反?
$results = DB::table('client')
->select(array(
'id_client', 'name', 'telephone',
DB::raw("MATCH(name) AGAINST (?) AS match")
))
->whereRaw("MATCH (name) AGAINST(?)")
->having('match', '>', 5.2)
->orderBy('match','desc')
->limit(10);
那里可能会有一些拼写错误,但这应该为您指明了正确的方向。
修正了一些错别字。
更新: 您可以尝试使用“匹配”,如下面的 2 个示例所示。不确定是否有效,因为我还没有测试过,但都尝试一下——第二个看起来更干净:
->where(DB::raw('MATCH(`some_field`)'),'AGAINST',DB::raw('("bar")'))
或者
->whereRaw('MATCH (some_field) AGAINST("bar")')
只需将栏替换为您想要匹配的内容即可。希望有帮助。
关于php - 有没有办法使用 Eloquent 来做出这样的陈述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23459731/