在eloquent orderBy()方法

时间:2016-12-09 05:59:07

标签: php eloquent laravel-5.2

我的数据库中有一个或多个产品需要根据updated_at字段进行排序。但我也希望在开始时查看缺少某些属性的产品。

例如,我想首先列出那些缺少描述或颜色的产品,然后根据更新日期对它们进行排序。此外,我想对它们进行分页,以便在从数据库中检索所有产品后对其进行排序。

那么有没有办法在Laravel中使用雄辩的方法来实现这一目标?

这就是我的products表格的样子,

products
    -id
    -style
    -title
    -description
    -colors
    -sizes
    -cost
    -weight
    -created_at
    -updated_at

1 个答案:

答案 0 :(得分:0)

你可以使用限制和跳过分页不确定,但你可以像这样使用你的问题..

function getProdcucts($skip, $limit){
           $list = DB::table('reports')->select()
                          ->where('colors', '=', null)
                          ->orWhere('description', '=', null)
                          ->orderBy('updated_at', 'desc')
                          ->skip($skip)
                          ->limit($limit)
                          ->get();
           return $list;
      }

不要一次获取所有记录,根据每页项目从db中获取记录。

相关问题