1

I am currently working on a small web application to gain some experience. Everything is going pretty well and i am in the process of testing some features. The app has a page with an HTML form where someone can type a PIN number and that will query a database for an item. That item will then be displayed in another page.(let's call that the "display page")

Now obviously i am using a POST route to use the PIN input and get the item.

Today as i was doing some tests a friend came over and tried to access the "display page" by just typing the url in the browser(/items/display). All i got was an error from Laravel that literally said "No message".

I do get that he tried to make a GET request when my route is POST but i have no idea what to do in order to deal with this. It isn't that important but i see it as a learning opportunity.

Any insight is appreciated. Thanks in advance!

Number 81
  • 11
  • 1
  • 2
  • 1
    Set `APP_DEBUG` in the `.env` to true and a detailed error message should be displayed. – Dan May 08 '19 at 13:44
  • 1
    Show your routes, Laravel shouldn't catch a GET request on a POST route, it should just pass down the request to the first route it matches. If it doesnt match any routes, it should throw an exception. – GTCrais May 08 '19 at 13:44
  • `obviously i am using a POST` - why? [Convention](https://stackoverflow.com/questions/504947/when-should-i-use-get-or-post-method-whats-the-difference-between-them) is to use `GET` to view something, and `POST` when *changing* something. You are simply retrieving data from a DB, which sounds like it should be `GET`. That will incidentally solve your problem :-) As well as mean you can share URLs that go directly to query results, like `http://somewhere.com/display/123`, or `http://somewhere.com/display?pin=123` – Don't Panic May 08 '19 at 15:44

1 Answers1

0

You can change yout route from Route::post('myurl') to Route::any('myurl'), so all HTTP verbs will route to your controller, including GET.

You can also change your route from post to get, Route::get('myurl'), and change your form to make a get request, adding the tag method="GET" to your form.

Ruby Junior Dev
  • 118
  • 1
  • 4