0
votes

Using Laravel 5.4 have this route in web.php

Route::post('foo/bar', function () {
    return 'Hello World';
});

but when I visit the http://localhost:8000/foo/bar URL in browser I have this error:

MethodNotAllowedHttpException in RouteCollection.php line 251: in RouteCollection.php line 251 at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 238 at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 176 at RouteCollection->match(object(Request)) in Router.php line 533 ...

I want to test a POST route method via the browser.

2
Use some sort of test extension. I use Postman on Chrome and it works (not 100% happy with it but it gets the job done). Alternatively you could use cURL on the Laravel built-in testing tools. - apokryfos

2 Answers

1
votes

Change it

Route::post(

to

Route::get(

and try again.

Explanation: Route::post() is used when we want to post the form with some data in it.

1
votes
Route::get('foo/bar', function () {
    return 'Hello World';
});

use this as you are not posting any data thus laravel is looking for data which is not present thus the error