Friendly URL for GET form in Laravel 4

2

My question is this: I have a search form (GET), and I would like to know how to execute submit sending those parameters to the URL in a friendly way.

Note: parameters are not required.

Form :

    {{ Form::open(array('route' => 'neighborhoods.city', 'class' => 'form-inline', 'method' => 'get')) }}

      <div class="form-group col-xs-2 col-lg-2 col-md-2">
        {{ Form::select('state_id', $states, 0, array('class' => 'form-control input-lg', 'id' => 'states')) }}
      </div>

      <div class="form-group col-xs-8 col-lg-8 col-md-8" id="cidades">
        {{ Form::select('city_id', $cities, 0, array('class' => 'form-control input-lg', 'disabled' => true)) }}
      </div>

      <div class="form-group col-xs-2 col-lg-2 col-md-2">
        {{ Form::submit('Buscar', array('class' => 'btn btn-default btn-lg btn-block btn-submit')) }}
      </div>

      {{-- Form::text('search', Input::old('search'), array('class' => 'form-control', 'placeholder' => 'Digite aqui o que você está procurando. Ex.: Encanador'))--}}
    {{ Form::close() }}
    
asked by anonymous 16.12.2013 / 18:04

3 answers

6

Automatically I do not know if there is any way, I believe not.

What you can do is, go through all elements of the form with javascript, mount the url, and make the browser redirect to the url with the mounted filters.

To stay friendly, you can do it in the format of named routes: link

It could be something like:

$("form input, form select").each(function(){
    arr[$(this).attr('name')] = $(this).val();
});

Another way is to use session for the filters, so you do not need to pass parameters by GET, nor do a POST with every page open.

    
16.12.2013 / 18:19
2

When it comes to a Search, I use conventional GET, but in case you need a search (Friendly), a suggestion would be, you create a page to handle the Search request, redirecting to the search result with the Amigavel model.

Example: Submit via Post or GET - > search? name = 1 & param2 = test
redirects to
search / 1 / test
search / name / test / param2 / test

It depends on your need.

    
16.12.2013 / 18:22
-3

Do you need these parameters to be passed by URL? Because I have search on my site, and use the following way my method:

downloads / bannersaldo

public function postBusca() {
    $word = Input::get('word');

    $articles = Article::where('title', 'LIKE', '%'.$word.'%')
        ->orWhere('body', 'LIKE', '%'.$word.'%')
        ->paginate(6);

    return View::make('articles.busca', compact('articles'));
}

The search data is passed in the variable and paginated. My URL is www.meusite.com/busca , only.

    
16.12.2013 / 18:16