7
I have a search on the site and I can opt for several filters and it already works by returning and paging correctly.
Example:
/empresas?estado=2&tipo=3&page=2
The problem is when I click order by a select form
, he doesn’t keep the URL
current, it simply does:
/empresas?ordenar=nome
It should be something like:
/business? status=2&type=3&sort=page=3
I made a append
, like paging does, but it still didn’t work.
In the 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 the View
:
I make a foreach
bringing the fields normally and do the append
with the render that already works
<center>
{!! str_replace('/?','?', $empresas->appends(Input::query())->render()) !!}
</center>
And I have an ordination form, maybe the mistake 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>
Post your code.
– Diego Souza
Is that your
combobox
is not rendered according to Laravel, right ?– Diego Souza
Exactly, and I don’t know how to put it in the append
– Eduardo Cruz
I think it would be the case to be able to play the current "Gets" in the form action, right? Type action="/companies? state=2&type=3". Does this work?
– Raylan Soares
It doesn’t work :( several sites have this "sort", but I can’t search, I don’t know the specific name. Probably have some package, or something like that.. but it’s hard to find.. rs Does anyone have any light, as you go? thanks
– Eduardo Cruz
You have to add the current parameters (which are in the current url) in your form action, or add inputs of type Hidden with the current url parameters in your form.
– Marcos Kubis
@Eduardocruz solved. Take a look at my answer :). Even if you have found another solution, it might be worth looking at, as learning
– Wallace Maxters
Which version is using Laravel 4 or Laravel 5?
– novic