Laravel: POST method returns MethodNotAllowedHttpException

There is a POST route in my api.php file, and it looks like this:

 Route::group( ['namespace' => 'api'], function () { Route::post('parent/signup', ' ParentController@signUp '); } ); 

And I'm trying to access this url in postman , as this is the api route. But when I send a request to this route , this exception occurs:

The NotAllowedHttpException method in the RouteCollection.php 218 line:

I am definitely sending an email request as shown in the image below:

enter image description here

I ran php artisan route:list and this route is POST.

 | POST | api\/parent\/signup | | App\\Http\\Controllers\\api\\ ParentController@signUp 

What am I doing wrong here? Any help?

+5
source share
2 answers

I have the same problem a month and a half ago.

The reason is that I am sending to a valid route, it redirects from http to https (configured to .htaccess), so the "POST" method becomes "GET" and you see a MethodNotAllowedException exception.

Check your browser and follow the request, you can see the exact problem.

+3
source

The problem should be the namespace of the routes, you are not using it correctly.

Try using the route group:

 Route::group(['prefix' => 'api'], function() { Route::post('parent/signup', ' ParentController@signup '); }); 
-1
source

Source: https://habr.com/ru/post/1272092/


All Articles