gpt4 book ai didi

php - Laravel Eloquent skip n, take all?

转载 作者:IT王子 更新时间:2023-10-29 00:10:39 27 4
gpt4 key购买 nike

我注意到在 Laravel 中链接 skip() 时,您还必须使用 take()。我想跳过前 n 行,但保留其余行。 take 方法只允许整数,我如何才能做到这一点而不诉诸于一些骇人听闻的技巧,例如为 take 指定一个大数字?

最佳答案

基本上,对于每个 OFFSET,必须为 mysql 提供一个 LIMIT 才能工作。因此,如果不指定限制,就无法做到这一点。我们需要一些 php mojo 才能在这里工作。

假设我们有一个名为 Attendance 的 Eloquent 类。这是应该起作用的:

//Getting count
$count = Attendance::count();
$skip = 5;
$limit = $count - $skip; // the limit
$collection = Attendance::skip($skip)->take($limit)->get();

关于php - Laravel Eloquent skip n, take all?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27457249/

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