Laravel eloquent select first 10 rows and another next 10 rows and so on

  eloquent, laravel, mysql

I’m trying to create a news feed like facebook..

What I intended to do is, on first load, I should get the first 10 rows… and I also have a show more button, when I click that button, It should select the next 10 rows starting from the end of the first 10 rows.

I’ve read about using this query

select * from `feed` limit <startIndex>,<NumberOfRecords>;

so I tried this eloquent query in my laravel api

feed = Feed::where('is_delete', 0)
        ->limit($request->index, 10) //Initial $reques->index == 0, next == 10, next == 20 and so on...
        ->orderBy('id', 'DESC')

but it doesn’t work…

Any idea?

Source: Laravel

Leave a Reply