Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4.1: Eloquent Offset & Limit

How to limit returned data from Eloquent? I tried with this:

$data = Product::all()->take(4)->skip(3);

And it return the error message: Call to undefined method Illuminate\Database\Eloquent\Collection::skip()

It seems like eloquent don't support skip()? So, how can I offset & limit the data from eloquent?

Thank you.

like image 980
user1995781 Avatar asked Feb 21 '14 01:02

user1995781


1 Answers

You may try this (get 4 items from offset 3/4th):

Product::take(4)->offset(3)->get();

Or this (get 5 items from 3rd row):

Product::take(5)->skip(2)->get();
like image 155
The Alpha Avatar answered Oct 05 '22 05:10

The Alpha