friendly url from laravel form 5.5

0

I have the following url with multiple filters given from a form

link

the url looks like that but I can not make it look like this

link

I'm using this but it does not work because since it's not a url, it's a request.

Route::get('/productos/{nombre_producto?}/{continente?}', 'ProductosController@GeneralProductos');
    
asked by Andersson Meza Andrade 03.07.2018 в 18:54
source

2 answers

0

The only way to pass data using a GET method is through query params (as you are doing):

Endpoint:

 GET https://localhost/productos?nombre_producto=un_nombre&continente=un_continente

If what you want is to "hide" that information from the view, it only occurs to me to make the call by POST sending the parameters in the body.

Endpoint:

POST https://localhost/productos

Headers:

Content-type: Application/json

Body:

{
  "nombre_producto" : "el nombre",
  "continente" : "un continente"
}

Obviously, it is not recommended to make calls POST just to consult data, it is recommended to make them using GET through query params.

    
answered by 04.07.2018 в 09:15
0

A possible solution would be using POST to call a function that creates the GET route that you want fast example:

Routes:

Route::post('/productos', 'ProductosController@buscar')->name('buscar');
Route::get('/productos/{nombre_producto?}/{continente?}', 'ProductosController@buscador')->name('buscador');

Controller:

 public function buscar(Request $request){
        return redirect()->route('buscador' , ['nombre_producto' => $request->nombre_producto, 'continente' => $request->continente]);
 }
 public function buscador(Request $request){
        $continente = $request->continente;
        $producto = $request->nombre_producto
        // Logica deseada
 }

Blade:

<form action="{{route('buscar')}}" method="post">
    {{csrf_field()}}
    <input type="text" name="nombre_producto">
    <input type="text" name="continente">
    <input type="submit" value="Buscar">
</form>
    
answered by 04.07.2018 в 12:30