0

I am developing a passport API in Laravel. I am getting a "MethodNotAllowedHttpException".

enter image description here

I don't get any idea, what fix do I have to do.

<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::post('register', 'Api\Auth\RegisterController@register');
Route::post('login', 'Api\Auth\LoginController@login');
Route::post('refresh', 'Api\Auth\LoginController@refresh');

Route::middleware('auth:api')->group(function () {
    Route::post('logout', 'Api\Auth\LoginController@logout');
    Route::get('posts', 'Api\PostController@index');
});
halfer
  • 19,824
  • 17
  • 99
  • 186
  • When visiting `register` in your browser, you're using `GET`, but your routes only permit `POST`. You will probably need `curl` or Postman to test your API. – halfer Aug 06 '17 at 08:19
  • I do have the same problem do you find any solution for this please let me know. – Abhee Sep 13 '17 at 13:35

2 Answers2

1

this error can occur due to request type (GET / POST) mismatch in your route and the request type in your API call or form tag in your view

  • check if the request type matched in your route file and in your APIcall
Umang Patel
  • 133
  • 3
0

See, you use 'post' method in your route:

Route::post('register', 'Api\Auth\RegisterController@register');

And the browser's default is 'get'. Are you trying to show a registration form or you are submitting a form to that route.

Either you should change that route to GET or create another route to show the page, then submit the form as post to the intended route