KeizerBridge
KeizerBridge

Reputation: 2757

How can I get data from a specific row to the rest of my table with Eloquent?

I would know how can I get a column for example from the Tenth line to the last of my table ? like this :

Model::where('foo', 'bar')->fromTo(FROM_TENTH_ELEMENT, TO_THE_LAST)->get()->toArray();

I know you can do a trick like this

Model::where('foo', 'bar')->take(count(Model::all()))->skip(10)->get()->toArray();

But it's too hard...

EDIT

Like elfif said using count method, the best solution.

Model::where('foo', 'bar')->take(Model::count())->skip(10)->get()->toArray();

Thank you.

Upvotes: 1

Views: 109

Answers (2)

elfif
elfif

Reputation: 1857

Answer depends on how do you want your table to be sorted at that time. Anyway here is what i would do

Model::where('foo', 'bar')->skip(20)->limit(10)->orderBy('id')->get()->toArray()

This will get 10 rows past the 20 first rows with the table ordered by id

Hope it helps !

Upvotes: 1

Ray
Ray

Reputation: 649

The easiest way coming to my mind is to fetch all items from your table first.

Then iterate over the result and eliminate the first ten items in laravel

Upvotes: 0

Related Questions