gpt4 book ai didi

php - Laravel 在给定 ID 后记录

转载 作者:行者123 更新时间:2023-12-04 16:31:37 24 4
gpt4 key购买 nike

我试图在给定的记录 ID 之后获取 10 条记录。

$media =  Media::where('active', '=', 1)->after('id',$after)->take(10)->get();

Laravel 中没有after 函数。还有其他方法吗?

最佳答案

使用另一个 where clause :

$media =  Media::where('active', 1) // don't need the "="
->where('id', '>', $after)
->take(10)
->get();

这将在 SQL 中构建以下查询(假设您的 $table 在 Media 模型中定义为“media”):

SELECT * 
FROM media
WHERE active = 1
AND id > $after
LIMIT 10

作为@lukasgeiter mentions ,您应该按 id 列对结果进行排序,因为如果不按语句排序,则无法保证结果的顺序。

关于php - Laravel 在给定 ID 后记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27766881/

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