skip to Main Content

I’m working on a countdown website where I have 2 forms in the same view, every time I submit 1 of those forms I’m getting a error that says:

"message": "The POST method is not supported for route /. Supported methods: GET, HEAD."

The method that I’m using in the view is a GET method and the method that I’m using in the action route of the forms are POST method.

Now, I’ll show you the routes and the HTML:

My routes:

routes

HTML Form 1:

html form 1

HTML Form 2:

html form 2

I’ve tried by setting the hidden method with Laravel using @method('POST') in the form, but it doesn’t even works, I’ve also tried setting the same route to the routes on the web.php file like this:

Route::get('/', function () {
    return view('welcome');
});


Route::post('/', [AppHttpControllersEmailController::class, 'sendEmail'])->name('send.email');
Route::post('/', [AppHttpControllersEmailController::class, 'saveEmail'])->name('save.email');

, but doesn’t works too, every time I tried it, I was getting this error:

error

and other things that I have tried by watching YouTube tutorials and StackOverflow posts, but how I said before nothing works

I would be very grateful if you could help me.

2

Answers


  1. Check if your expected route is listed when you call
    php artisan route:list

    if your route is present in the list use the below in your view form action:
    action={{url(contact-form)}}

    Login or Signup to reply.
  2. Add method="post" to your form tag.

    <form action="{{ route("...") }}" method="post">
    

    And check if Laravel cached your view or route, run php artisan about and see if it is cached.

    It will show like this:

    Cache ...............................................................................  
      Config ................................................................... NOT CACHED  
      Events ................................................................... NOT CACHED  
      Routes ................................................................... NOT CACHED  
      Views .................................................................... NOT CACHED  
    

    If it’s cached, run php artisan view:clear to clear view cache, php artisan route:clear to clear routes cache.

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