I have a search on the site and I can opt for several filters and this already works by returning and paging correctly.
Example:
/empresas?estado=2&tipo=3&page=2
The problem is when I click to sort by a select form
, it does not hold the current URL
, it simply does:
/empresas?ordenar=nome
Should be something like:
/ companies? status = 2 & type = 3 & sort = name & page = 3
I made a append
, as the pagination does, but it still did not work.
No Controller
:
$estados = DB::table('estados')->orderBy('nome', 'asc')->get();
$tipos = DB::table('tipos')->orderBy('nome', 'asc')->get();
$word = Input::get('query');
$ordenar = Input::get('ordenar');
$estado = Input::get('estado');
$tipo = Input::get('tipo');
$query = Empresas::with('usuario')->with('estado');
if($word)
$query->where('descricao', 'LIKE', '%' . $word . '%')
->orWhere('carta', 'LIKE', '%' . $word . '%');
if($estado)
$query->whereIn('estado_id', $estado);
if($tipo)
$query->where('tipo_id', $tipo);
if($ordenar)
$query->orderby($ordenar, 'asc');
$empresas = $query->orderBy('updated_at', 'desc')->paginate(18);
return view("pages.empresas.index")
->with('estados', $estados)
->with('tipos', $tipos)
->with(compact('empresas', 'word', 'ordenar', 'estado','tipo'));
In View
:
I make a foreach
bringing the fields normally and I make append
with the render that already works
<center>
{!! str_replace('/?','?', $empresas->appends(Input::query())->render()) !!}
</center>
And I have a form to sort, maybe the error is in it
<form action="/empresas" method="get">
<select class="form-control m-b" name="ordenar" onchange="this.form.submit()">
<option value="" disabled="" selected="">Ordenar por...</option>
<option value="nome">Nome</option>
</select>
</form>