I've noticed that in Laravel when chaining a skip()
you must also use take()
as well. I want to skip the first n rows but take the rest. The take method only allows integers how can I do this without resorting to some hacky trick such as specifying a large number for take?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Basically, with every OFFSET, a LIMIT must be supplied for mysql to work. Therefore, there is no way to do this without sepcifying a limit. We need some php mojo to work here.
Let's say we have an Eloquent Class named
Attendance
. Here's what should work:I think this is not a good answer, because you're forcing to do two queries, the right way will be:
You can see more about collections here
If you're using MySQL and you don't want to have 2 queries to get the max rows, you may use the PHP maximum INT value as
take()
parameter e.g.take(PHP_INT_MAX)
.It's because Laravel Query Grammar casts the limit to integer. So you can't use a larger number than that.
From MySQL documentation on LIMIT:
For example: