Problems with route response in the Laravel

Asked

Viewed 27 times

0

I am learning Laravel, and has an exercise where you pass two routes with the same address in the '/contact' case but with two different parameters, a GET another POST, and for each parameter a different Return as a response, only to learn even routes, however, my code (Laravel 5.8) can only respond to the post method, even if this set as GET, the answer that enters is from the post... Even using the Controller still yes, enters the POST

Route::get('/contato/{id?}' , ['uses'=>'ContatoController@index']);
Route::get('/contato',['uses'=>'ContatoController@criar'] );
Route::post('/contato',['uses'=>'ContatoController@editar'] );

Controller:

    public function index()
   {
      return "Esse é o Index do ContatoController";
    }
    public function criar()
   {
      return "Esse é o Criar do ContatoController";
    }
    public function editar()
   {
      return "Esse é o editar do ContatoController";
    }

Form:

<div>
                <h2>Teste com Rotas</h2>
                <form method="POST" action="/contato">
                @csrf
                <input type="text" name="nome" placeholder="Nome / POST">
                <button>Enviar</button>   
                </div>

                <div>
                <h2>Teste com Rotas</h2>
                <form method="GET" action="/contato">
                @csrf
                <input type="text" name="nome" placeholder="Nome / GET ">
                <button>Enviar</button>
                </div>             
  • When you fire the form with method "GET", it returns the answer of the POST function "edit()" is that what’s happening ? in the GET method I believe you don’t need @csrf only for POST.

  • Exactly that

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.