4
How do I join query string in the 4-way pagination?
For example: I have a data listing and on this screen I have a search filter. When I send a get to request the filter in the list by the url
http://localhost/lista-de-produtos?marca=1
,
the data is listed as requested, but when I go to page 2 the paginate removes the parameter mark=1 from the url and adds pag=2, then the filter does not work.
Follow the code of the consultation:
$registros = Produtos::where(function ($query) {
if (Input::has('nome')) {
$nome = Input::get('nome');
$query->where('nome', 'LIKE', "%{$nome}%");
}
if (Input::has('marca')){
$marcaId = Input::get('marca');
$query->where('marca_id', '=', $marcaId);
}
})->paginate(20);
There have been people who have used
http_build_query
to do this. But in Laravel you don’t have to. It’s all beautiful. See the answer ;)– Wallace Maxters