The skip($n)
method is indeed not included in the Collection
class, but there is a function that does the same: slice($n)
.
QueryBuilder (taken from the documentation):
$users = DB::table('users')->skip(10)->take(5)->get();
Alternatively, you may use the limit and offset methods:
$users = DB::table('users')
->offset(10)
->limit(5)
->get();
Collection:
collect([1, 2, 3, 4])->slice(2)->all(); //[3, 4]
Many of the methods in the QueryBuilder
class are not available in the Collection
class, and vice-versa. But both of them have similar functions, like QueryBuilder
's where
function, you'd use Collection
's filter
function to achieve similar results.