简体   繁体   English

Laravel重新组织RESTful API

[英]Laravel reorganising a RESTful API

In a Laravel project I have a RESTful API that has been poorly organised. 在Laravel项目中,我有一个组织不好的RESTful API。 I wish to reorganise this, and I intend to update all current references to the API, but there is a chance that I will miss some things, or other branches when merged in may be broken. 我希望对此进行重组,并且打算更新所有当前对API的引用,但是有可能我会错过一些东西,或者合并后的其他分支可能会损坏。 Therefore, ideally the pages I move I would like to still work (until I am confident we can remove them) but throw a warning to the logs stating that it is a deprecated URL and to update the code to use the new one. 因此,理想情况下,我要移动的页面仍然可以工作(直到我确信我们可以删除它们),但是向日志发出警告,指出它是已弃用的URL,并更新代码以使用新的URL。 There are about 20 pages I am moving. 我正在移动大约20页。

What would be the easiest way to implement this? 实现此目的的最简单方法是什么? One way would be to make 20 more functions that are just: 一种方法是增加20个仅是的功能:

function a() {
    Log::warning("This is an old method blah blah blah");
    aNew();
}

But this seems like a very messy way to do so. 但这似乎是一种非常混乱的方式。

Thanks. 谢谢。

You could create a filter and just add it to the before key on all your routes that you are phasing out. 您可以创建一个过滤器,然后将其添加到要淘汰的所有路线上的before键。

Route::get('old_api_function', array('uses' => 'ApiController@oldFunction', 'before' => 'old_api'));

Route::filter('old_api', function($route, $request, $value)
{
    Log::warning("This is an old method blah blah blah: ".$route);
});

And this should log the route that you want to phase out. 这应该记录您要逐步淘汰的路线。

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

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