Php 如何在拉雷维尔做到这一点与雄辩和db

Php 如何在拉雷维尔做到这一点与雄辩和db,php,laravel,eloquent,Php,Laravel,Eloquent,如何在拉雷维尔做到这一点与雄辩和db SELECT thread.threadid, MATCH(thread.title) AGAINST ('title_seatch_word') AS score FROM thread AS thread WHERE MATCH(thread.title) AGAINST ('title_seatch_word') AND thread.open <> 10 " . iif($threadid, " AND thread.t

如何在拉雷维尔做到这一点与雄辩和db

SELECT thread.threadid, MATCH(thread.title) AGAINST ('title_seatch_word') AS score
FROM  thread AS thread
WHERE MATCH(thread.title) AGAINST ('title_seatch_word')
    AND thread.open <> 10
    " . iif($threadid, " AND thread.threadid <> $threadid") . "
LIMIT 5
所以我想要完整的查询使用以下方法:

Thread::select('threadid')
    ->selectRaw('MATCH (`title`) AGAINST (?) AS score', ['title_search_word'])
    ->where('open', '<>', 10)
    ->when(isset($threadid), function ($query) {
        return $query->where('threadid', '<>', $threadid);
    })
    ->havingRaw('`score`') // OR: ->having('score', '>', 0)
    ->take(5)
    ->get();
Thread::select('threadid')
->选择raw('MATCH('title')与(?)匹配为分数,['title\u search\u word'])
->其中('open','',10)
->当(isset($threadid),函数($query){
返回$query->where('threadid','','threadid');
})
->havingRaw('score')//或:->having('score','>',0)
->采取(5)
->get();

这样,
score
只需计算一次。

您可以使用
->select('thread.threadid',DB::raw(“MATCH(thread.title)对('title_seatch_word')作为分数”)
编写sql Complete您能就答案给出反馈吗?
SELECT thread.threadid, MATCH(thread.title) AGAINST ('title_seatch_word') AS score
Thread::select('threadid')
    ->selectRaw('MATCH (`title`) AGAINST (?) AS score', ['title_search_word'])
    ->where('open', '<>', 10)
    ->when(isset($threadid), function ($query) {
        return $query->where('threadid', '<>', $threadid);
    })
    ->havingRaw('`score`') // OR: ->having('score', '>', 0)
    ->take(5)
    ->get();