Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip and take all?

In eloquent, how can I skip 10 rows and then get the rest of the table?

User::skip(10)->all();

The above does not work, but it gives you an idea what I am looking for.

like image 317
panthro Avatar asked Aug 12 '16 09:08

panthro


2 Answers

Try this:

$count = User::count();
$skip = 10;

User::skip($skip)->take($count - $skip)->get();

With one query:

User::skip($skip)->take(18446744073709551615)->get();

It's ugly, but it's an example from official MySQL manual:

To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;
like image 123
Alexey Mezenin Avatar answered Oct 07 '22 02:10

Alexey Mezenin


try something like this it work for sure..

$temp = User::count();
$count = $temp - 10;

$data = User::take($count)->skip(10)->get();
like image 32
Jaimin Avatar answered Oct 07 '22 01:10

Jaimin