1

I am new to laravel, the problem I have encountered is post request is not working with the postman. I have spent the whole day on this error but nothing worked. Maybe I am making a mistake somewhere. Your help will be appreciated.

I also have tried it by disabling the following code in Kernel.php

// \App\Http\Middleware\VerifyCsrfToken::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,

api.php

Route::post('country', 'Country\CountryController@countrySave');

Controller.php

 public function countrySave(Request $request){

    $country = CountryModel::create($request->all());
    return response()->json($country, 200);
}

web.php

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

Following is the error

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The POST method is not supported for this route. Supported methods: GET, HEAD. in file C:\xampp\htdocs\laravel_tutorial\blog\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php on line 256

Saveen
  • 4,120
  • 14
  • 38
  • 41

1 Answers1

0

The routes in "api.php" are only used when the url is in the format "yoursite.com/api/yourRoute". See this answer to another question.

Laravel is looking for a POST route in "web.php", where you only have the single GET route. You should look at modifying the URL to tell Laravel you want the "api.php" routes.

Grant C.
  • 346
  • 1
  • 7
  • I am using correct root and formatting. Secondly I have post and get routes with different method names. get route working fine. Problem is with post route. –  May 15 '19 at 06:34