Laravel 5.4: POST API routes give MethodNotAllowedHttpException

Active3 hr before
Viewed126 times

5 Answers


Meta Stack Overflow , Stack Overflow help chat ,It gives me this error: Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException!, Stack Overflow Public questions & answers

That's stupid, right? Yea, I know! Also make sure if your app is on a SSL domain, always connect to https:// instead of http://. Because it is not only secure but also a redirection may happen again, without you knowing it! How? By your own .htaccess file that you have changed or your hosting support has changed it for you and you don't remember (check this answer as well):

# Let 's force using SSL on all of our URLs and also forbid non-secure POSTs

RewriteEngine On

# Forbid non - secure POSTs
RewriteCond % {
} != on
RewriteCond % {
} = POST
RewriteRule ^ / [F,L]

# Force SSL
RewriteCond % {
} != on
RewriteRule ^ https: //%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you would like a route parameter to always be constrained by a given regular expression, you may use the pattern method. You should define these patterns in the boot method of your RouteServiceProvider:,You can even define parameter constraints for the named parameters in your prefix:,You can also utilize the prefix parameter to pass common parameters to your routes:,If you need to access a route parameter value outside of a route, use the input method:

Basic GET Route

Route::get('/', function() {
   return 'Hello World';
load more v

Auth\LoginController.php:,With our current strategy, if the token is wrong or missing, the user should receive an unauthenticated response (which we’ll implement in the next section). So for a simple logout endpoint, we’ll send in the token and it will be removed on the database.,We’ll also run the migrations before each test. This setup will allow us to build the database for each test and then destroy it, avoiding any type of dependency between tests.,In our config/database.php file, we’ll need to set up the database field in the sqlite configuration to :memory::

As with all modern PHP frameworks, we’ll need Composer to install and handle our dependencies. After you follow the download instructions (and add to your path environment variable), install Laravel using the command:

$ composer global require laravel / installer
load more v

So we can now ensure Laravel uses the right route by doing this,So on redirect intended i get error MethodNotAllowedHttpException. URL is correct which is defined as POST method. What am I missing here? Why does laravel redirects intended as GET method? How could I solve this problem? Thanks!,return redirect()->guest(route('user.getAdditionalFields'));,Also note that its not possible to redirect a POST because Laravel expects form to be submitted. SO you can't do this:

This is how my middleware redirect looks like:

return redirect() - > guest('user/additional-fields');

This redirect appears on successfull log in:

return redirect() - > intended();


Route::post('/user/log-in-post', ['as' => 'user-log-in-post', 'uses' => 'UserController@postUserLogIn']);
load more v

Hi , Ï am Creating oauth server in Laravel 5 using bshaffer method. As a result I am using below URL in Postman,I am getting the same issue in the post man,the same error throws in my local server but when online its throws the same error. what might be the problem. am using laravel 5.3 and php 7,You're likely trying to access the endpoint as a GET but haven't set it up properly in your Laravel routes.

You're likely trying to access the endpoint as a GET but haven't set it up properly in your Laravel routes.

Here is one example of what that could look like:
Route::get('oauth/token', 'YourController@yourMethod');

Route::get('oauth/token', 'YourController@yourMethod');
load more v

Other "undefined-undefined" queries related to "Laravel 5.4: POST API routes give MethodNotAllowedHttpException"