简体   繁体   中英

Why does a Laravel resource controller limited to update generate two routes?

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\SmokerController@update |
| PATCH | profile/smoker/{smoker}|                       | App\Http\Controllers\Profile\SmokerController@update |

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\SmokerController@show |

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM