0
votes

I have the next trouble I have a form, and when I click to register button, show me the next:

"The GET method is not supported for this route. Supported methods: POST."

But my method is POST, this is my Route:

Route::post('/createpedido',[
'uses'=>'PedidosControlador@pedidoagregado',
'as'=>'Pedidos.pedidoagregado']);

And this is part of my blade

            <form method="post" action="{{route('Pedidos.pedidoagregado')}}" enctype="multipart/form-data">
            {{csrf_field()}}
            <div class="row text-center">

                <div class="col-lg-12 col-sm-12">
                    <h2>Agregar Pedido</h2>
                    <h3>Cliente: {{$Clientes->nombreempresa}}</h3>
                </div>

                <div class="col-lg-6 col-sm-6">
                    <h2>Datos Pedido</h2>
                    <hr size="5" color="#FF0000" />

And this is my complete controller

   public function pedidoagregado(Request $request)
{
    $validator = Validator::make($request->all(), [
        'pedido' => 'required|string|max:255',
        'fechapedido' => 'required|date|max:255',
        'fechaentrega' => 'required|date|max:255',
        'tipopedido' => 'required|string|max:255',
        'observaciones' => 'required|email|max:255',
    ]);

    if ($validator->fails()) {
        return redirect('/createpedido')
            ->withErrors($validator)
            ->withInput();
    }

    $pedido = $request['pedido'];
    $fechapedido = $request['fechapedido'];
    $fechaentrega = $request['fechaentrega'];
    $tipopedido = $request['tipopedido'];
    $observaciones = $request['observaciones'];
    $idcliente = $request['idcliente'];

    $pedidos = new Pedidos();

    $pedidos->idcliente = $idcliente ;
    $pedidos->npedido = $pedido;
    $pedidos->fechapedido = $fechapedido;
    $pedidos->fechaentrega = $fechaentrega;
    $pedidos->tipopedido = $tipopedido;
    $pedidos->observacones = $observaciones;
    $pedidos->save();

    $request->session()->flash('alert-success', 'Pedido Agregado Correctamente');

    if(Auth::user()->userlevel == "admin"){
    return redirect()->to('administrador/');
    }

    if(Auth::user()->userlevel == "ventas"){
        return redirect()->to('ventas/');
    }

}

Thanks for your help

1
Can we see your whole form? It might be an issue further down where you submit. Also, have you issued composer dump?Drewster
hello @Beto, have you tried closing the <form> tag?Suomynona

1 Answers

0
votes

I check your code, which you provided and everything is fine. I guess, there is a probability you make two routes one get the form and second for post route for posting your data to the server.

and perhaps by mistake, you give same alias to both routes.

You give method post so whether you give same alias it should work, perhaps you forget to close form tag or by mistake, you have another form inside your form. Perhaps there is some issue with route cache. so clear it with artisan command.

php artisan route:clear

Perhaps This will work, there is some probability you did something wrong, so I suggest you recheck all part I included in the answer.