如何使用多个 where 语句和 orderby 2 类型进行 Eloquent 查询,并对其进行分页或限制?
PostIco::table('posts')
->where('listingType', '!=', 1)
->OrderBy('listingType', 'created_at')
->limit(25)
->paginate(10)
如何让它发挥作用?
最佳答案
PostIco
是一个 Eloquent 模型吗?如果是这样,则不要对其使用 table
方法。
PostIco::where('listingType', '!=', 1)
// Instead of OrderBy
->orderBy('listingType', 'asc')
->orderBy('created_at', 'desc')
->limit(25)
->paginate(10);
您还可以使用DB
外观来做到这一点:
DB::table('posts')
->where('listingType', '!=', 1)
->orderBy('listingType', 'asc')
->orderBy('created_at', 'desc')
->limit(25)
->paginate(10);
编辑:更正 orderBy 语句
关于mysql - Eloquent 进行长查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49831047/