HUGE_DICK_10_INCHES's avatar

How to handle multiple paginations with one link

In basic pagination we get some next url for loading more data, but if those data have more data with pagination as well, how can I customize and use different parameters for different data:

?page=2 to ?posts=2&comments=1

I am using api resource with main UserResource which returns posts with PostsResource which uses pagination and returns CommentsResource whicch uses pagination as well.

0 likes
4 replies
HUGE_DICK_10_INCHES's avatar
Level 5

@SNAPEY - I am using api resource and its similar to yours:

 'posts' => PostsResource::collection($this->posts()->paginate(1, ['*'], 'posts', $request->query('posts'))),
 'total' => $this->posts()->paginate(1, ['*'], 'posts')->total(),

I am returning this from UserResource.

But since I am using resource and not collection because I cannot customize collection output, I cannot get pagination data only way I added above, is there any other way?

Snapey's avatar

If its an API then you should probably have a separate end point for each resource and pull them independently according to the current page for each.

Please or to participate in this conversation.