Problems with routes in Laravel

1

I have a small problem with one of my routes ...

I have my index which shows me several products (9 to be exact) when selecting one of my products therefore my route changes with the specification of my product example: "store \ donuts" in the donuts view I have a small form to get in touch with me to give reports of the products.

My problem arises when filling out my form and sending it to my BD my route changes to "store \ thank-contact" and I would like that depending on the product I choose the route show me the message of thanks along with the product that select example "store \ dona \ thank-contact" and as all my forms I have them linked to a single controller at the time of sending always send me to "store \ gracias-contacto" I do not know how to generate dynamic routes or if that is the best option or if there is an even simpler I leave part of my code

<form action="{{URL::to('save-contact-info')}}" method="POST" id="formulario">
                        {!! csrf_field() !!}
                        <div class="title-form">
                            <h3>
                                Informes
                            </h3>
                        </div>
                        <div class="info-form">
                            <div class="form-group">
                                <label>Nombre:</label>
                                <input type="text" name="nombre" class="form-control input-lg">
                            </div>
                            <div class="form-group">
                                <label>Email:</label>
                                <input type="text" name="email" class="form-control input-lg">
                            </div>
                            <div class="form-group">
                                <label>Teléfono:</label>
                                <input type="text" name="telefono" class="form-control input-lg">
                            </div>
   <input type="hidden" name="producto" value="Donas">
                            <div class="form-group">
                                <button class="btn btn-lg btn-solicitar" type="submit">
                                    Enviar
                                </button>
                            </div>
                        </div>
                    </form>

these are my routes

Route::get('donas', 'reposteriaController@donas');

Route::get('pasteles', 'resposteriaController@pasteles');

Route::post('save-contact-info', 'reposteriaController@saveContactInfo');


/*-- Lograr madar el modelo por la url--*/

Route::get('gracias-contacto', 'reposteriaController@gracias');

and these are my controllers

  public function donas(){
            return view('donas');
        }

        public function pasteles(){
            return view('pasteles');
        }

        public function saveContactInfo(Request $request){

            $nombre         = $request->input('nombre');
            $email          = $request->input('email');
            $telefono       = $request->input('telefono');
            $modelo         = $request->input('modelo');

            $nuevo_usuario  = new ContactoReposteria;
                $nuevo_usuario->nombre      = $nombre;
                $nuevo_usuario->email       = $email;
                $nuevo_usuario->telefono    = $telefono;
                $nuevo_usuario->modelo      = $modelo;
            $nuevo_usuario->save();

            $datos          = array(
                'nombre'        => $nombre,
                'email'         => $email,
                'telefono'      => $telefono,
                'modelo'        => $modelo
            );

            Mail::send('front.contacto-reposteria', $datos, function($message) use ($datos){
                $message->to('[email protected]')
                ->subject('Contacto Reposteria');
            });

            return redirect('gracias-contacto');
        }

        public function gracias(){

              return view('front.gracias');
        }
    }

As you can see I have two types of products here and I would like to be able to pass the model name through the route so that I can identify which product is selected and depending on the product it is displayed in my url "tienda {modelo- product} \ thanks-contact "

Thanks in advance for your help and your suggestions !!!!

    
asked by Bahamut4321 23.08.2018 в 18:09
source

2 answers

2

Try doing something like this:

On your routes:

Route::get('/tienda/{producto}/gracias-contacto', 'reposteriaController@gracias')->name('gracias-contacto');

And in your controller when you redirect, do this:

return redirect()->route('gracias-contacto', ['producto' => $nombre_producto]);

Take into account that if there are products with accents, blank spaces or special characters, you should put them in a friendly way for the URL. For that you could convert the name of the product into a slug using a laravel helper:

$nombre_producto = "pastel de chocolate";

str_slug($nombre_producto, '-');

// Te imprimiría pastel-de-chocolate

    
answered by 23.08.2018 / 18:38
source
1

Route

Route::get('/modelo/{modelo}/gracias-contacto', 'reposteriaController@gracias');

Controller

public function saveContactInfo(Request $request){

    $nombre         = $request->input('nombre');
    $email          = $request->input('email');
    $telefono       = $request->input('telefono');
    $modelo         = $request->input('modelo');

    $nuevo_usuario  = new ContactoReposteria;
        $nuevo_usuario->nombre      = $nombre;
        $nuevo_usuario->email       = $email;
        $nuevo_usuario->telefono    = $telefono;
        $nuevo_usuario->modelo      = $modelo;
    $nuevo_usuario->save();

    $datos          = array(
        'nombre'        => $nombre,
        'email'         => $email,
        'telefono'      => $telefono,
        'modelo'        => $modelo
    );

    Mail::send('front.contacto-reposteria', $datos, function($message) use ($datos){
        $message->to('[email protected]')
        ->subject('Contacto Reposteria');
    });

    return redirect('/modelo/{modelo}/gracias-contacto',['modelo' => $modelo]);

}

and this is my driver where you direct me to the view of thanks

public function gracias($modelo){

          return view('front.gracias');
    }

and this is the error that votes me

InvalidArgumentException in Response.php line 458: The HTTP status code "1" is not valid.

    in Response.php line 458
    at Response->setStatusCode(array('modelo' => 'Dona')) in Response.php line 202
    
answered by 23.08.2018 в 19:16