Do you mean like this?
$users = DB::table('users')->skip(10)->take(5)->get();
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.
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]
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community