Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

Do you mean like this?

$users = DB::table('users')->skip(10)->take(5)->get();

Last updated 1 year ago.
0

Looking at the api docs you use the offsetGet method.

$user = User::where('age', '>', '20')->orderBy('id', 'asc')->get()->offsetGet(3);

ofc where 3 is the number of the offset you want. I do the orderBy since when I query things they will sometimes come up in the wrong order (mainly with hasMany relationship stuff.) So if you aren't worried about that then feel free to omit it.

Last updated 1 year ago.
0

Garbee said:

Looking at the api docs you use the offsetGet method.

$user = User::where('age', '>', '20')->orderBy('id', 'asc')->get()->offsetGet(3);

ofc where 3 is the number of the offset you want. I do the orderBy since when I query things they will sometimes come up in the wrong order (mainly with hasMany relationship stuff.) So if you aren't worried about that then feel free to omit it.

OffsetGet works from a zero index so you'd want to get the value using -> offsetGet(2)

Also php php5.4 allows you to access function results using array syntax directly

$user = User::where('age', '>', '20')
  ->orderBy('id', 'asc')
  ->get()[2]
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

meneman meneman Joined 7 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.