skip to Main Content

I’m new to Laravel! I’ve encountered the error "The GET method is not supported for route contact. Supported methods: POST" in a form. I’ve tried several corrections but without success.

web.php

route::post('/contato', [ContatoController::class, 'contato'])->name('app.contato');

ContatoController.php

class ContatoController extends Controller
{
    public function contato( Request $request){
        dd($request);
        return view('app.contato');
    }
}

contato.blade.php

<form action="{{ route('app.contato') }}" method="post">
        @csrf
        <label for="nome">Nome:</label>
        <input type="text" id="nome" name="nome">
        
        <label for="email">Email:</label>
        <input type="email" id="email" name="email">
        
        <label for="mensagem">Mensagem:</label>
        <textarea id="mensagem" name="mensagem"></textarea>
        
        <button type="submit">Enviar</button>
    </form>

Here is a screenshot of the error:
screenshot

2

Answers


  1. A possibility is because of the URL of your post route could same as the view you are trying to return. I can’t tell if the URL you are sending the request from is the same as the URL you are receiving the POST request from, but if it is, that is where your issue lies. When making POST routes you should ensure to define the URL more clearly:

    route::post('/contato/store', [ContatoController::class, 'contato'])->name('app.contato.store');
    

    If the URL is the same, and it is trying to access it during a POST request, it will throw that error.

    Login or Signup to reply.
  2. When we "open" a web page usually it’s made via a GET request, it may be missing your GET route to send the request to your view.

    I think your routes must be something like this:

    route::view('/contato', 'contato');
    route::post('/contato', [ContatoController::class, 'contato'])->name('app.contato');
    

    PS

    I’m assuming your view is on root.

    If you need to send some data to your view you may need to go to the controller first.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search