maryam
maryam

Reputation: 584

Cannot access POST route in Laravel via browser

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.

Upvotes: 0

Views: 1254

Answers (2)

Exprator
Exprator

Reputation: 27503

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

Upvotes: 1

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

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.

Upvotes: 1

Related Questions