Help with laravel pager

1

Good evening to the whole community, I have the following problem with the laravel pager, I am doing a query by means of a controller to a database on sql server, the query is as follows:

$ data = VistaAHUMA00017 :: whereBetween ('DateDate', [$ request- > start_date, $ request- > end_date]) -> whereBetween ('HoraTime', [$ request- > start_time, $ request- > end_time]) - > paginate (10);

This shows me my records correctly paged in the view, the problem comes when I go to the second page, for some reason it seems as if I had no data, however if you have more data to paginate, I attach an image:

What I do not understand, is that when I put fixed data, without passing variables on the query, the page works perfectly, according to what I have reached to detect is that it stops working by passing the variables to make the query , it is as if when going to the next link the variables no longer serve, this has only happened to me with sql server, in mysql it has always worked perfectly for me ...

    
asked by Sebastian Rodriguez 05.09.2018 в 02:41
source

1 answer

0

The first is that as far as I can see in the error is that you are trying to access a route by the wrong method, you need to put in your question the route you are occupying and the HTML of the pager part.

Remember that by the time you are using filters, such as the dates and times of your data, you should be sending them to the pager so that each page takes them into account and does not get lost, for example:

If you put only this {{ $registros->links() }} in your view to print the pager and your URL is the following: www.abc.com?fecha_inicial=2018-09-05 , your url would be only as www.abc.com?page=1,2,... at the time of paging and ignore the additional parameters, the solution would be to put your pager as follows:

{{ $registros->appends(['fecha_inicial' => $datos['fecha_inicial'], 'fecha_final' => $datos['fecha_final'], 'hora_inicial' => $datos['hora_inicial'], 'hora_final' => $datos['hora_final']])->links() }}

(I clarify that if you do not have those variables defined in the view it would give you an error, and you would have to validate that they exist with a ternary operator for example.)

This way I would apply for a route using the GET method and if you are doing it with POST I would not recommend it since first, the POST method should not be returning a view, which apparently, I believe that you are sending the filters of a form by the POST method after you are returning the view with the filtered data and when clicking on some link of the pager, you will get that error since a link accesses a route using the method GET and yours is in POST .

    
answered by 05.09.2018 в 22:54