Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kbrk's avatar
Level 1

MethodNotAllowedHttpException for Post Request

I've two ajax post request called 'signIn' and 'signOut' in laravel 5.4 .

I'm using jwt authentication (tymondesigns/jwt-auth) instead of csrf so I closed VerifyCsrfToken middleware line in Kernel.php

There are four routes in the project.

Route list ( php artisan route:list );

Method  |URI    |Action                    | Middleware 
GET|HEAD| /     |Closure                   | web 
GET|HEAD| home  |Closure                       | web
POST    |signOut|App\Http\Controllers\APIController@signOut| web 
POST    |signIn |App\Http\Controllers\APIController@signIn | web

Route;


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

Route::get('home', function () {
    return view('main');
})->name('home');

Route::post('signIn', 'APIController@signIn');
Route::post('signOut', 'APIController@signOut');

The process;

User sign in the account and then the home page is called in an ajax request success via window.location.href='home' ( 127.0.0.1:8000/home ) .

The sign out button is pressed and signOut is called.

Sign Out Request;

 $.ajax({
            type: 'POST',
            url: 'signOut',
            data: data,
            dataType: 'JSON'
})

signIn is working perfectly but signOut send 500 error.

Request URL:http://127.0.0.1:8000/signOut
Request Method:POST
Status Code:500 Internal Server Error
Remote Address:127.0.0.1:8000

The description of error;

MethodNotAllowedHttpException in RouteCollection.php

in RouteCollection.php line 233
at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 220
at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 1

APIController;

..
use Illuminate\Http\Request;
..

public function signIn{..}

public function signOut{..}

I'm using Wamp in Windows 10

I also tried other types of request but result is the same.

Do you have any advice ? Thank you.

0 likes
4 replies
SaeedPrez's avatar

No one can help you without wildly guessing when you change the actual code that is causing the problem.

Here's my guess, make sure you don't have a trailing slash in the URL when sending the ajax request.

kbrk's avatar
Level 1

@SaeedPrez Thank you for your advice. I tried to be more specific. I edit the network header and the route list. I don't think that I cut the url if I'm not wrong.

Snapey's avatar

Let me see, what is different here;


blah blah blah working blah
blah blah blah notworking blah

oh, I know, one of them says notworking

Please or to participate in this conversation.