简体   繁体   English

为什么限于更新的Laravel资源控制器会生成两条路由?

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

Given the following defined route in routes.php : 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. 我可能会猜测,在安静的环境中, PUTPATCH动词都足够接近,以致它们都受到“更新”限制。 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 . 我找不到任何文档来支持这种猜测,也找不到任何文档说明为什么一个(PUT)会自动将其别名设置为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. 更重要的是混乱,是一个类似的限制,“秀”,结果在动词GETHEAD被合并为GET|HEAD路由列表中。

| 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? 为什么GETHEAD合并,而PUTPATCH不合并?

The RFCs define the differences between PUT vs PATCH, and the information for that is out there. RFC定义了PUT与PATCH之间的区别,有关该信息,请参见。 One example is the answer linked to in the comments ( example ). 一个示例是评论中链接到的答案( 示例 )。 However, for the Laravel framework, there really is no difference. 但是,对于Laravel框架,确实没有什么区别。

In regards to your second question, why PUT and PATCH are not merged in the routes, it is really just an oversight. 关于您的第二个问题,为什么PUT和PATCH不在路径中合并,这实际上只是一个疏忽。 This oversight has been corrected in Laravel 5.2, according to this pull request . 根据此拉取请求 ,此疏忽已在Laravel 5.2中得到纠正。 Therefore, as of 5.2, the PUT and PATCH routes should show up merged, just like the GET and HEAD routes. 因此,从5.2开始,PUT和PATCH路由应显示为合并,就像GET和HEAD路由一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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