php - 将特定记录设置为行第一行 Laravel 查询生成器

标签 php laravel laravel-4

我想设置所有记录按FIELD_NAME排序,但首先只需要保留1条具有特定id的记录。

我如何使用laravel查询生成器来实现这一点

我当前的查询是这样的,

$orders =Order::orderBy('status', 'desc')
  ->where('status','<>',5)
  ->paginate(10);

我希望 id=123 首先留下来。

最佳答案

使用orderByRaw和简单的sql条件:

        $orders = Order::orderByRaw('IF(id = 123, 0,1)')->orderBy('status', 'desc')
            ->where('status', '<>', 5)
            ->paginate(10);

关于php - 将特定记录设置为行第一行 Laravel 查询生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36498188/

相关文章:

php - PDO 动态查询构建

php - mysql 多联表sql修改

PHP $_POST 变量不处理由 Javascript 生成的输入字段

php - Laravel 后 Controller 不工作(Symfony\Component...)

laravel - IronMq + Laravel4 : How make it working

php - Laravel 4 队列

PHP 函数从数据库中提取字段值

php - Laravel hasOne 通过数据透视表

Laravel 调度程序 : Should I use jobs or commands?

ajax - Auth::check() 在 ajax 调用中失败(有时)