Laravel 5.x 版本升级 6.x

更新日期: 2020-07-17 阅读次数: 5198 字数: 566 分类: Laravel

需要将一套历史悠久的 laravel 5.0 / 5.2 系统,升级到 laravel 6 LTS 版本。同时,对应的 PHP 版本也要升级到最新的 PHP 7.4。由于代码量巨大,且逻辑多得看不过来,需要一套高效的策略来升级。

laravel 升级策略

官方只提供了 5.8 到 6 的升级建议

https://laravel.com/docs/6.x/upgrade

于是 Google 了一通,发现普遍的建议是,采用逐个小版本升级的方式。

To be honest you should make update step by step. First upgrade 5.2 to 5.3, then to 5.4 and so on... Each version has little difference. Take a look this page. You have manual how to do it. https://laravel.com/docs/5.3/upgrade Then read: https://laravel.com/docs/5.4/upgrade and so on... That is why so important to make upgrading regularly.

https://stackoverflow.com/questions/60372578/how-to-upgrade-from-laravel-5-to-laravel-6

You can find upgrade guides on the Laravel documentation. You need to upgrade one version at a time: 5.2 -> 5.3 5.3 -> 5.4 5.4 -> 5.5 (Additional step for 5.5 -> 5.5.42) 5.5 -> 5.6 (Additional step for 5.6 -> 5.6.30) 5.6 -> 5.7 Also, you should probably clear the cache before upgrading: Delete everything in /bootstrap/cache/files Clear cache php artisan cache:clear Clear view cache just in case php artisan view:clear

https://stackoverflow.com/questions/54275711/laravel-upgrade-issue-from-5-2-to-5-7/54275788#54275788

协同开发策略

由于前端也在同步开发,如何能不影响到前端的开发呢?

付费服务

laravel shift 自动升级服务。

但是,看了一下,感觉不妥。

因为对应企业级代码来说,让三方服务去修改代码,有泄露代码的风险。这个风险太大,不知道冒险。

如何直接跨版本升级呢

我还是觉得逐个版本升级太繁琐。例如,完整看完 5.2 升级 5.3 文档,并做了主要改动的兼容修改,两个小时过去了。。。而且我还是忽略了 DB::table 返回 collection 与 array 的差异,忽略了一两个我没完全看懂的点。如果较真起来,耗时应该更久。

所以,我觉得这样搞其实非常耗费时间。

远不如这样:

  • 看一遍所有升级文档。并记录下一些改动比较大的点,忽略基础框架文件的变更(这些修改反而是繁琐而没有意义)。
  • 然后新建一个最新版本的项目目录,把 model, controller,router 解决。但是需要对原项目代码比较了解。了解项目功能结构是有必要的。

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式