Ad

Laravel 5.2 : MethodNotAllowedException

- 1 answer

I've defined the following route in Laravel:

Route::group(['prefix' => 'api'], function() {
    Route::post('login', [
        'uses' => 'Auth\[email protected]',
        'as' => 'auth.login',
    ]);
});

And I'm using Postman to send a request like this (you can also see the results):

enter image description here

Why am I getting a MethodNotAllowed exception???? I also tried creating a form in an empty html file, with the method set to post. but got the same results.

EDIT

If i add a route::get that shows a login form, after the post request in Postman it shows that login form.

enter image description here

EDIT 2:

output of php artisan route:list for our route entries:

+--------+----------+--------------+---------------------+----------------------------------------------------+------------+
| Domain | Method   | URI          | Name                | Action                                             | Middleware |
+--------+----------+--------------+---------------------+----------------------------------------------------+------------+
|        | GET|HEAD | /            | guest.home          | App\Http\Controllers\[email protected]         |            |
|        | GET|HEAD | a/dashboard  | admin.dashboard     | Closure                                            |            |
|        | POST     | api/login    | auth.login          | App\Http\Controllers\Auth\[email protected]     |            |
|        | GET|HEAD | api/login    | auth.login          | Closure                                            |            |
|        | GET|HEAD | api/logout   | auth.logout         | App\Http\Controllers\Auth\[email protected] | jwt.auth   |
|        | POST     | api/register | auth.register       | App\Http\Controllers\Auth\[email protected]  | jwt.auth   |
|        | GET|HEAD | m/dashboard  | moderator.dashboard | Closure                                            |            |
|        | GET|HEAD | pu/dashboard | premium.dashboard   | Closure                                            |            |
|        | GET|HEAD | u/dashboard  | user.dashboard      | Closure                                            |            |
+--------+----------+--------------+---------------------+----------------------------------------------------+------------+

EDIT3

One more curious thing. If i set the method to Route::any, I get rid of the exception, but then I can't access the post parameters. i.e. I don't have any post parameters.

EDIT 4:

If I add a route::get and show the login view there and send the login credential, it works. But not in Postman.

Ad

Answer

Unfortunately the problem was with Postman3. I'm using Advanced REST Client now, and it works alright. Postman would send GET requests no matter what method I chose.

Ad
source: stackoverflow.com
Ad