gpt4 book ai didi

mysql - Eloquent 进行长查询

转载 作者:行者123 更新时间:2023-11-29 06:45:09 26 4
gpt4 key购买 nike

如何使用多个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com