laravel orderByRaw() on the query builder

前端 未结 1 1830
日久生厌
日久生厌 2021-01-17 11:56

there is no way to make such a query(with the binding) using the Laravel query builder right now:

SELECT * FROM `posts` WHERE MATCH( `title`         


        
相关标签:
1条回答
  • 2021-01-17 12:33

    Using Eloquent you can do the following:

    $match = "
        match (
            `title`,
            `description`
        ) against (
            ?
            IN BOOLEAN MODE
        )";
    
    $against = 'bar';
    
    $sql->whereRaw($match, array($against));
    $sql->orderByRaw($match . " DESC", array($against));
    

    The same would work with the Query Builder, but then you have to do a little rewriting.

    0 讨论(0)
提交回复
热议问题