panthro
panthro

Reputation: 24061

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.

Upvotes: 5

Views: 1726

Answers (3)

Alexey Mezenin
Alexey Mezenin

Reputation: 163858

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;

Upvotes: 3

Autista_z
Autista_z

Reputation: 2541

Laravel 5 returns Eloquent result as Collection. So you can use collenction function slice();

$users = User::get();
$slicedUsers = $users->slice(10);

Upvotes: 1

Jaimin
Jaimin

Reputation: 872

try something like this it work for sure..

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

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

Upvotes: 2

Related Questions