Skip to content

how can make a custom pagination api #41513

Answered by mikeydevelops
Haythamfpco asked this question in Q&A
Discussion options

You must be logged in to vote

I have dug in to the source of Resources and ResourceCollections and come up with a plan.
Together with my previous response and this you will achieve your desired result.

  1. First you have to make a base resource, I will call it BaseResource for the example, which extends the original JsonResource, allowing you to overwrite methods.
  2. Then place the BaseResource somewhere I will use App\Http\Resources\BaseResource.
  3. Go through all your resource classes and change class ... extends JsonResource to class ... extends BaseResource.
  4. Copy the definition of the collection method from the JsonResource and place it in your BaseResource.
  5. Rename the new AnonymousResourceCollection with new CustomResourc…

Replies: 6 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@Haythamfpco
Comment options

@getsolaris
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Haythamfpco
Comment options

You must be logged in to vote
1 reply
@mikeydevelops
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@HuyNguyen206
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants