简体   繁体   中英

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.

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 !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM