I am trying to implement pagination in my user index page, but I think it is breaking because the pagination logic adds meta data into the user data, so the UserDTO.fromArray(users) ends up returning an empty array. I was reading online that one way to handle it is make a fromPaginator function in the User DTO class. Is that the best way to handle it? What is the recommended way we paginate when using DTOs?
Here's the logic in my user controller that is coming back empty:
async index({ request, inertia, auth }: HttpContext) { const page = request.input('page', 1) const users = await User.query().orderBy('username', 'asc').paginate(page, 10) return inertia.render('admin/users/index', { users: UserDto.fromArray(users), }) }
Copied!