且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

laravel orderByRaw()在查询生成器上

更新时间:2022-05-16 19:20:39

使用雄辩,您可以执行以下操作:

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.