Pagination is inconsistent for collections #51085
-
When an api resource collection is paginated, the structure of the pagination is not consistent with if it were a query result. From the doc: https://laravel.com/docs/11.x/pagination, pagination without resource collection does not wrap the meta information in a "metas" key as seen in this structure: But, for resource collections, the structure is different, as the meta information about the number of pages are wrapped in "metas", even if the Does anyone know I can make the pagination of the resource collection have same structure as the regular pagination as I need to maintain consistency in my APIs. I am thinking of customizing the pagination information as stated here: https://laravel.com/docs/11.x/eloquent-resources#customizing-the-pagination-information, but, I fear it will still keep the meta and that will be duplication of data on the responce. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Hi. You can use macros to overwrite the default behavior.
As you can see this is not macroable so you must check where it is called and see if it could be overwritten with custom logic. PS. We created a restful crud lib to solve this: https://packagist.org/packages/macropay-solutions/laravel-crud-wizard-free |
Beta Was this translation helpful? Give feedback.
-
Thank you... At least now I see "How" Laravel does it, I will try to see how I can override it. |
Beta Was this translation helpful? Give feedback.
-
Solved by writing a macro on the JsonResource class, using the defination provided by @macropay-solutions
|
Beta Was this translation helpful? Give feedback.
Solved by writing a macro on the JsonResource class, using the defination provided by @macropay-solutions