Inherit from an instance of CursorPaginator #45613
Unanswered
pimeo
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi.
I post my message here because it's more an evolution than a bug.
Most of apis i'm developing use pagination system but not use the next and previous pagination urls attributes. Pagination datas are passed to a json body contents including
page
andper_page
attributes. In order to do not display theses attributes, I must extend theLengthAwarePaginator
in my application and rewrite thetoArray
method (exemple above). And once I have fetched my records usingpaginate
method, I recreate a new instance with own extendedLengthAwarePaginator
class and send it as response. Maybe it's not a pretty solution in the Laravel best practises but in my case, for security reasons, I have installed from Illuminate repositories only packages I need to run my application (my ecosystem is also a little bit different from a standard Laravel application). It works well in this way.Example of my "extended"
LengthAwarePaginator
class:Yesterday, I tried to do the same thing with created my own inherited
CursorPaginator
class :In order to return an formatted array like this :
Extending this class is possible but when it's time to instanciate my extended
CursorPaginator
class from the original, I lost next and previous cursors. That's due to thesetItems
method in constructor which overrides the $items property by removing items from per page property.Actual behavior:
items
,perPage
,cursor
etgetOptions
methods to create the new instance.Expected behavior:
**getOriginalItemsCollection**
,perPage
,cursor
etgetOptions
methods to create the new instance.The expected behavior needs to make changes to the CursorPaginator class:
This is the edited Illuminate CursorPaginator instance (my code uses illuminate pagination v8.83.5 at this moment):
And then try to make a new instance, I can write my instructions like this:
What do you think about this evolution?
Thank for reading.
Beta Was this translation helpful? Give feedback.
All reactions