1

I don't know exact difference between POST and PUT method.Some of the people said on internet that when you update record at time you have to use PUT method instead of POST, i don't know is it true??

form Internet if your website URL in POST method 1. www.example.com/user/{id}/update :- PUT use 2. www.example.com/user/update :- POST use this is right or not ??

Zobjoys Jeirmov
  • 181
  • 1
  • 5
  • 16
  • Does this answer your question? [What's the difference between a POST and a PUT HTTP REQUEST?](https://stackoverflow.com/questions/107390/whats-the-difference-between-a-post-and-a-put-http-request) – Sehdev Feb 17 '20 at 06:46
  • I am asking which method should i use in laravel when i update record – Zobjoys Jeirmov Feb 17 '20 at 06:49

2 Answers2

5

If you're inserting a new data you'll most likely use POST method

Route::post('new/data', 'NewDataController@store');

If you want to edit or add a new data that is not existing, you must use PUT method

Route::put('/data', 'NewDataController@update');
Louie Albarico
  • 230
  • 1
  • 3
  • 11
0

The difference in implementation is just the phrase used, if you wanted to go according to the docs though, you should be using PUT for the first one and POST for the latter. [https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6][1]

  • PUT: www.example.com/user would create a new entity
  • PUT: www.example.com/user/{id} would update an existing entity
  • POST: www.example.com/user a data-accepting endpoint (such as batch updating where id's are defined in body and not in URI)

I hope this helps :)

Neibesh
  • 121
  • 2
  • 5
  • Also if it helps (From W3) :P The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource. – Neibesh Feb 17 '20 at 07:20