6
votes

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

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

And I am trying to access this url in postman as this is an api route. But when I send request to this route, this exception occurs:

MethodNotAllowedHttpException in RouteCollection.php line 218:

I am definitely sending a post request as shown in the shot below:

enter image description here

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

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

What am I doing wrong here? Any help?

2
Why do you add public in your url? Standard Laravel applications are served from public, but you don't need to add it to the url. Could you try example.com/api/parent/signup?JiFus
Without public it returns 404 error.Saani
whats you method name signup or signUp??Mr. Pyramid
its signUp. As shown.Saani
what headers you send with postman?Giacomo M

2 Answers

9
votes

I have a same problem on a half of month ago.

The reason is when I post on valid route, it redirects from http to https (configured by .htaccess), so "POST" method becomes "GET" and you see a MethodNotAllowedException.

Check your browser and follow the request, you may see the accurate problem.

-1
votes

The problem should be the route namespace, you are not using it properly.

Try to use the route group:

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