Rediska's avatar

How to get N records from a collection?

Greetings to all! Can you please tell me how to get records from the collection, for example, from 11 to 20 out of 30, sorted by some parameter?

There are, for example, 30 products. To get the 10 cheapest ones, I do this:

$products->sortBy('price')->take(10)

To get the 10 most expensive ones, I do this:

$products->sortByDesc('price')->take(10)

And how can I get goods from 11 to 20?

0 likes
2 replies
Rediska's avatar

Seems to have found a way. If I'm wrong - correct me)) Thank you!

$products->sortBy('price')->skip(10)->take(10)
1 like

Please or to participate in this conversation.