Error paging in laravel 5.4

1

I have an error when paging the data, just load the first page and then give me a MethodNotAllowedHttpException .

I've been spinning around and I can not solve it.

Route:

Route::post('estados/resultado','consultasController@searchestado')->name('consultas.estado.search');

Controller:

public function searchestado (Request $request){
    $consulta = Order::Estado($request->state, $request->orden, $request->modo)->paginate(5);
    return view('resultadoConsulta')->with('order',$consulta);
}

Scope:

public function scopeEstado($query,$estado,$orden,$modo){
    return $query->where('state','=',$estado)
                 ->where('user_id','=',\Auth::user()->id)
                 ->orderBy($orden,$modo);
}

Loading everything without paging works well , try paging in the socope and I also did not work properly.

I load the values indicated in paginate (5) and the navigation between pages is rendered correctly but the contents of the other pages are not loaded.

I leave a DD in the controller before returning the data to the view:

I have other pages that work correctly, I am relatively new with this framework and there is something I am missing, I have consulted the documentation but I can not solve it.

Maybe it should not be with POST because when I add the? page = 2 it generates the error?

Try GET and it did not work either, when changing pages, the parameters of the query were deleted.

POST URL:

/consultas/estados/resultado
/consultas/estados/resultado?page=2

GET URL:

/consultas/estados/resultado?state=En+Camino&orden=buy_date&modo=desc
/consultas/estados/resultado?page=2

Error message when changing pages:

    
asked by César Alejandro M 15.08.2017 в 08:11
source

1 answer

1

Paging should preferably be handled by GET, and to preserve the search parameters when changing pages, you should call the paging links in this way if you do so in the view:

{{ $order->appends(request()->input())->links() }}

This line what it does is add the input parameters of the current request obtained with the helper request()->input() by means of the method appends() to the instance of the paginator $order , and by last calls the link generator links() which is nothing but an alias of render() .

    
answered by 15.08.2017 / 17:20
source