Skip to content
Advertisement

Decrementing row count with Laravel pagination (not Incrementing)

I want to display the row count of a decrementing paginated collection in Laravel, I have searched a lot, and there are methods to do it incrementing order, but not decrementing.

Explaining the issue:

Using Laravel 8.x, I have a controller method like this (simplified):

JavaScript

In my view, I display the data in a table like this

JavaScript

And finally the pagination links

JavaScript

Currently, even though I have a orderBy('id','DESC') and the first result in table is actually the last data, I am displaying the row count (#) in table like this:

Page 1:

JavaScript

Page 2:

JavaScript

But what I want to do is to display the row count in reverse

Because first result displayed is actually the last result (orderBy('id','DESC')).

Like this:

Page 1:

JavaScript

Page 2:

JavaScript

How can I achieve this?

P.S. I cannot just use the ID, as there are gaps in between results because of the WHERE clause.

Advertisement

Answer

In case any one else needs to do this, here is the solution:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement