Ad

Why Does A Laravel Resource Controller Limited To Update Generate Two Routes?

- 1 answer

Given the following defined route in routes.php:

Route::resource('smoker','SmokerController',['only' => ['update']]);

..results in the generation of two distinct routes:

| PUT   | profile/smoker/{smoker}| profile.smoker.update | App\Http\Controllers\Profile\[email protected] |
| PATCH | profile/smoker/{smoker}|                       | App\Http\Controllers\Profile\[email protected] |

I can hazard a guess that both PUT and PATCH verbs are close enough in a restful environment that they both fall under an 'update' restriction. I can't find any documentation to support that guess, nor can I find anywhere documentation why one (PUT) has it's alias automatically set, in this case, to profile.smoker.update.

What is more confusing, is that a similar restriction, 'show', results in a verbs GET and HEAD being merged as GET|HEAD in the route list.

| GET|HEAD | profile/smoker/{smoker}| profile.smoker.show | App\Http\Controllers\Profile\[email protected] |

Why is GET and HEAD merged, but PUT and PATCH not?

Ad

Answer

The RFCs define the differences between PUT vs PATCH, and the information for that is out there. One example is the answer linked to in the comments (example). However, for the Laravel framework, there really is no difference.

In regards to your second question, why PUT and PATCH are not merged in the routes, it is really just an oversight. This oversight has been corrected in Laravel 5.2, according to this pull request. Therefore, as of 5.2, the PUT and PATCH routes should show up merged, just like the GET and HEAD routes.

Ad
source: stackoverflow.com
Ad