I have an error when paging the data, it only loads the first page and then it gives me a MethodNotAllowedHttpException .
I've been tossing it around and can't figure it out.
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 pagination works fine , I tried to paginate in the socope and the pagination did not work correctly either.
It loads me the values indicated in paginate(5) and the navigation between pages is rendered well but the content of the other pages is not loaded.
I leave a DD in the controller before returning the data to the view:
I have other paginations that work fine, I'm relatively new to this framework and there's something I'm missing, I've looked at the documentation but can't figure it out.
Maybe it shouldn't be with POST because adding the ?page=2 generates the error?
I tried with GET and it didn't work either, when I changed the page the parameters of the query were deleted.
POSTURL:
/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
Pagination should be handled by GET preferably, and to preserve search parameters when switching pages, you should call pagination links like this if you do it in the view:
What this line does is add the input parameters of the current request obtained with the helper
request()->input()
through the methodappends()
to the pager instance$order
, and lastly it calls the link generatorlinks()
which is nothing more than an alias ofrender()
.