1

I'm new to Laravel but learning fast. The documentation about Routing says the following:

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);

I can code in PHP and know what POST and GET requests are. And also know how to update and delete records via SQL. But why are there so many Route types, aren't POST and GET enough?

And in which situations should I use the PUT, PATCH, DELETE or OPTIONS route?

Thanks in advance.

Theo

Dirk
  • 3,095
  • 4
  • 19
  • 37
  • To build trivial api's and websites, POST and GET are enough. When you want to specify the same route using RESTful API's for full crud they aren't. This is the HTTP1.1 specification and those verbs you mention have been around and in use for a long time. – David Barker Apr 14 '16 at 19:16
  • Have a read: http://stackoverflow.com/questions/8785248/which-browser-support-rest-completely-means-get-post-put-and-delete-method – yardie Apr 14 '16 at 19:19
  • Possible duplicate of [What's the difference between a POST and a PUT HTTP REQUEST?](http://stackoverflow.com/questions/107390/whats-the-difference-between-a-post-and-a-put-http-request) – Josh Rumbut Apr 14 '16 at 20:13

1 Answers1

2

That is because it follows the architecture defined by REST specification. The Laravel documentation explains it a little and also shows a table of which method uses what. But, basically, it is:

  • GET -> retrieve a resource or its collection
  • POST -> create one or many resources
  • PUT -> update a whole resource or many of them
  • PATCH -> update a chunk of one or many resources
  • DELETE -> delete one or many resources (although deleting many is not wise)
  • OPTIONS -> shows the options available for the specified resource
henriale
  • 1,012
  • 9
  • 21