You*_* K. 24
基本上,对于每个OFFSET,必须提供一个LIMIT才能使mysql工作.因此,没有分割限制就没有办法做到这一点.我们需要一些php mojo才能在这里工作.
假设我们有一个名为Eloquent Class的人Attendance
.这应该是什么工作:
//Getting count
$count = Attendance::count();
$skip = 5;
$limit = $count - $skip; // the limit
$collection = Attendance::skip($skip)->take($limit)->get();
Run Code Online (Sandbox Code Playgroud)
如果您正在使用 MySQL 并且您不想有 2 个查询来获取最大行数,您可以使用 PHP 最大 INT 值作为take()
参数,例如take(PHP_INT_MAX)
.
这是因为 Laravel Query Grammar将限制转换为 integer。所以你不能使用比这更大的数字。
要检索从某个偏移量到结果集末尾的所有行,您可以为第二个参数使用一些大数字。
例如:
\App\User::skip(10)->take(PHP_INT_MAX)->get();
Run Code Online (Sandbox Code Playgroud)