I do not see the purpose behind the PUT and DELETE http verbs. I have seen a tutorial at https://scotch.io/tutorials/simple-laravel-crud-with-resource-controllers and have not seen the power of a PUT nor DELETE methods when to it comes to a database based application. Why would I bother to write a PUT route in my application when I paste in the exact same code into a POST route in my application?
1 Answers
There's no particular power to using one over another, the benefit here is mostly semantic.
Although REST conventions are not enforced, those conventions are used to offer a "standardized" way of accessing RESTful resources (though the accepted norm may differ slightly for different people).
The HTTP methods (verbs) used by RESTful web services are defined by RFC2616. According to that definition the verbs do hold some inherent semantic value:
By definition the
PUT
andDELETE
methods are idempotent (meaning that the result of a particular request using that method will be the same each time your run it), whilePOST
requests on the other hand are not.
Consider some of the routes generated by Laravel's Route::resource()
method:
+--------+---------------------+------------------+-------------------------------+
| Method | URI | Name | Action |
+--------+---------------------+------------------+-------------------------------+
| POST | resource | resource.store | ResourceController@store |
| GET | resource/{resource} | resource.show | ResourceController@show |
| PUT | resource/{resource} | resource.update | ResourceController@update |
| DELETE | resource/{resource} | resource.destroy | ResourceController@destroy |
+--------+---------------------+------------------+-------------------------------+
The route with the POST
method will create a new resource entry so it requires no unique identifier to be specified in the route, but if you look at the other three definitions you can see the semantic value of using specific methods to make requests on the same resource. So if you were to make a request to:
http://domain.com/resource/1
The request would do different things depending on the HTTP method:
GET
will will return the resource with ID1
PUT
will will modify/update the resource with ID1
DELETE
will will destroy the resource with ID1
This means that regardless if your resource is puppies, cars or documents, you know that using different verbs on the same URL will have expected effects.
This is not a standard you're required to code by, it's just something that a lot of people agree with. And since Laravel in some respects is an opinionated framework, it offers this particular way of handling resources out of the box.
Of course there's nothing stopping you from using POST
for all routes, as that would work just fine (you'd need a different URL path for each action but in the end the result would be the same).

- 43,166
- 12
- 128
- 129
-
1Well said. I think following the resource controller standard makes your routes cleaner, coding easier to read/follow and it's more laravelish. Sure you `could` use POST for everything but you could also use raw php for everything in Laravel. Neither are very laravelsih. – Will Bowman Mar 06 '16 at 22:47
-
1@gcphost thank you for your comment. I like receiving answers and explanations to 'best practices' questions and Bogdan and yourself have done a fabulous job at that. Thank you both. It's starting to click in. – alaboudi Mar 07 '16 at 01:05