You can use the forPage method on the Eloquent query builder to paginate the results and position the cursor on the last page. The forPage method takes two parameters: the page number and the number of results per page. To position the cursor on the last page, you can use the lastPage method to get the total number of pages and then pass that as the first parameter to the forPage method.
@jlrdw@mohamedtammam I was searching for a way to use ->paginate() and setting manually the page parameter passed by the pagination system on the last page number.
But to do this I have to know how many pages there are and this is not possible before querying the database.
@Snapey That's true, I didn't thought about it, effectively I might get a single entry. What would be better is to retrieve the last 10 results for example or perhaps the results for the last month.
It's for a personal project to learn how to manage float number, so I'm trying to develop a very very simple accounting application to store only the incomes, expenses and fees without any other feature.
And the aim is to display all transactions ordered by date ascending, but on the first page load directly see the last page.
@vincent15000 a strong tip. never handle money with floats. its imprecise and leads to rounding issues, particularly when calculating percentages
decide on the lowest denomination that suits your app and use that. For most shopping carts this might be cents. Multiply the data up when displaying. So something costing $11.75 would be held as integer value 1175
Occasionally, in some industries where things are bought in large volumes , the price per unit might be $0.075 so the system would then need to be all in 10ths of a cent
@Snapey I don't handle money with floats, I use integers. I convert integers to floats only to display the amounts in the views. But in my mind, when I said that I need to handle floats, for me storing floats as integers is a way to handle floats efficiently to not have problems with rounding.