Hello All.
I am new to laravel.
Route::get('/', [UserController::class, "Userindex"]);
Route::post('/', [UserController::class, "UserProcessLogin"]);
These are my routes. When I post to this route by form, it always goes to the get route in the form , my action is:
<form action="{{url('/')}}" method="post">
But Post Route is not working, this is working with the other route, but not with the same route.
When I Test the same process with Postman Or thunder Client, they are returning Good results, as I worked.
Please Help me.
My Answer:
It seems like you may be experiencing a common issue with Laravel routing where the POST request is being treated as a GET request. This can happen if there is a redirect happening or if there is a middleware that is interfering with the request.
One thing you can try is to use the `@csrf` directive in your form to include a CSRF token. This is required for POST requests in Laravel to prevent CSRF attacks. Your form should look like this:
html
If that doesn't solve the issue, you can try adding the `csrf` middleware to your route to ensure that the CSRF token is validated properly. Update your routes like this:
php
Route::post('/', [UserController::class, "UserProcessLogin"])->middleware('csrf');
If the issue still persists, you may want to check if there are any other middleware or redirects that could be causing the POST request to be treated as a GET request. You can also try clearing your route cache by running `php artisan route:clear` in your terminal.
I hope this helps resolve your issue with the POST routing in Laravel. Let me know if you have any other questions.
Rate this post
4 of 5 based on 4448 votesComments