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:
HTML Form 1:
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:
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
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)}}
Add
method="post"
to yourform
tag.And check if Laravel cached your view or route, run
php artisan about
and see if it is cached.It will show like this:
If it’s cached, run
php artisan view:clear
to clear view cache,php artisan route:clear
to clear routes cache.