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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.