Saturday, March 18, 2017

MethodNotAllowedHttpException for Post Request

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

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('singIn', 'APIController@singIn');
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.



via kbrk

Advertisement