Support the ongoing development of Laravel.io →
Requests Database
Last updated 2 years ago.
0

Here is my suggestion: your REST API should be something like: /api/posts?start={start_id}&size={size_of_list}

Set a default value for start (0) and size (50) if nothing is provided as part of the REST API.

IF start == 0 query_posts->where('id', '>', start)->orderBy('id', 'desc')->take(size) else query_posts->where('id', '<', start)->orderBy('id', 'desc')->take(size)

when you iterate through the results, set the last id as the new start id.

good luck!

Last updated 2 years ago.
0

Well the way I create feeds in mobile apps is have a api request that get's all the latest feed posts. Then handle the pagination in the mobile language. I thought about what your doing saving the spot and calling another request when the user want's to load more posts but it seemed like that's a very inefficient way and could add up in calls to the api.

My answer only works if you want to get 50 posts at first then another 50 when the user scrolls down? I might not be understanding your question though?

Good luck on your project.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

KarlPi karlpi Joined 20 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.