6

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?

Saani
  • 791
  • 7
  • 28
  • 68

2 Answers2

9

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.

trinvh
  • 1,500
  • 2
  • 11
  • 20
  • O man, you saved my day. That was exactly the issue. I changed it to `https://` and it worked. Thanks a lot. Cheers! – Saani Sep 25 '17 at 12:47
  • I also have the same issue! And I'm also connecting to `https://` when I'm hitting the API! But the POST method still doesn't work: `https://example.com/app/public/api/test`. Can you explain more on this? – Ali Oct 31 '17 at 22:28
  • @Saani what was the solution? Do i have to update my .htaccess file? what do i have to update with? I am having the exact same problem – Reaz Patwary Mar 22 '18 at 02:45
-1

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');
});
Giacomo M
  • 4,450
  • 7
  • 28
  • 57