将Laravel 5.0升级到最新版本(7.x) [英] Upgrading Laravel 5.0 to the latest version (7.x)

查看:63
本文介绍了将Laravel 5.0升级到最新版本(7.x)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被分配了一个旧的Laravel项目(版本5.0).第一项任务是将Laravel从版本5.0 升级到最新的版本7.x (截止到今天).

I have been assigned with an old Laravel project (version 5.0). The first task is to upgrade the Laravel from version 5.0 to the latest version 7.x (as of today).

从Laravel文档中,我发现这将需要一个痛苦的漫长过程!我知道有一项名为 Laravel Shift 的付费服务,因为这是巨大的版本转移,因此将涉及一笔不菲的费用.因此,Laravel Shift对我来说不是一个选择.

From the Laravel docs, i found out that it's gonna take a painful long process! I know that there's a paid service called Laravel Shift, that will involved quite a huge money as this is huge version jump. So, Laravel Shift is not an option for me.

我可以安装最新版本的Laravel,并从旧版本中复制并粘贴所有MVC文件吗?有没有人做过这种方法并立即成功?

Can I install the latest version of Laravel, and copy and paste all the MVC files from the old version? has anyone done this method and succeed right away?

谢谢.

推荐答案

首先,让我们将php 升级到至少7.2.5,以下命令适用于7.4

First, let's upgrade php to at least 7.2.5 Given below commands are for 7.4

sudo apt-get update
sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt -y install php7.4
sudo apt-get install -y php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip,xml,curl,json}
php -v
sudo update-alternatives --set php /usr/bin/php7.4
sudo a2enmod php7.4
sudo systemctl restart apache2

要进行验证,请检查{url}/phpinfo.php

For verification, check {url}/phpinfo.php

第二,删除 composer.lock 文件&供应商文件夹 rm -R供应商.运行 composer install .

Second, remove composer.lock file & vendor folder rm -R vendor. Run composer install.

第三,这就是一切的地狱!升级后代码更改

Third, and this is where everything goes to HELL!! Changes in code after upgrade

1)具有方法
$ request-> has方法现在将返回true,即使输入值为空字符串或null.添加了新的$ request-> filled方法,该方法提供has方法的先前行为.
例如

1) The has Method
The $request->has method will now return true even if the input value is an empty string or null. A new $request->filled method has been added that provides the previous behaviour of the has method.
e.g.

array:1 [
  "class_teachers" => null
]

$request->has('class_teachers')
true

$request->filled('class_teachers')
false


2).从html页面标题中删除html特殊字符.


2) Remove html special characters from html page title.


3)嵌套三元操作
必须明确使用括号来指示操作顺序.


3) Nested Ternary Operations
Must explicitly use parentheses to dictate the order of the operations.

1 ? 2 : 3 ? 4 : 5;       // deprecated
(1 ? 2 : 3) ? 4 : 5;     // ok
1 ? 2 : (3 ? 4 : 5);     // ok


4)或运算符
Blade的"or"运算符已被删除,取而代之的是PHP的内置??.空合并"运算符


4) The or Operator
The Blade "or" operator has been removed in favor of PHP's built-in ?? "null coalesce" operator

$user->name or "-"  -->   $user->name ?? "-"


5)输入外观

'Input' => Illuminate\Support\Facades\Input::class,  -->  'Input' => Illuminate\Support\Facades\Request::class,


6)不建议使用带有花括号的数组和字符串偏移量访问语法

$str = "test";
echo $str{0};  // deprecated
echo $str[0];  // ok


7)使用计数列格式
使用别名时,withCount方法将不再自动将_count附加到结果列名称上.


7) withCount Column Formatting
When using an alias, the withCount method will no longer automatically append _count onto the resulting column name.


8)记录
现在,所有日志记录配置都位于其自己的config/logging.php配置文件中.您应该将默认配置文件的副本放置在自己的应用程序中,然后根据应用程序的需要调整设置.


8) Logging
All logging configuration is now housed in its own config/logging.php configuration file. You should place a copy of the default configuration file in your own application and tweak the settings based on your application's needs.

log和log_level配置选项可以从config/app.php配置文件中删除.

The log and log_level configuration options may be removed from the config/app.php configuration file.

use Illuminate\Support\Facades\Log;
Log::info('Showing user profile for user: '.$id);


9)排队
QUEUE_DRIVER 环境变量已重命名为QUEUE_CONNECTION .除非您有意修改config/queue.php配置文件,否则这不会影响要升级的现有应用程序.并将默认的QUEUE_CONNECTION更改为数据库


9) Queue
The QUEUE_DRIVER environment variable has been renamed to QUEUE_CONNECTION. This should not affect existing applications that you are upgrading unless you intentionally modify your config/queue.php configuration file. And change default QUEUE_CONNECTION to database

还更改.env文件(非常重要)

Also change .env file (VERY IMPORTANT)


10)TTL(秒)

// Laravel 5.7 - Store item for 30 minutes...
Cache::put('foo', 'bar', 30);

// Laravel 5.8 - Store item for 30 seconds...
Cache::put('foo', 'bar', 30);


11)碳2.0 Laravel现在支持Carbon 1和Carbon 2.因此,如果未检测到与任何其他软件包的其他兼容性问题,Composer将尝试升级到Carbon 2.0.请查看 Carbon 2.0迁移指南.


11) Carbon 2.0 Laravel now supports both Carbon 1 and Carbon 2; therefore, Composer will try to upgrade to Carbon 2.0 if no other compatibility issues with any other packages are detected. Please review the migration guide for Carbon 2.0.


12)whereDate方法
查询构建器的whereDate方法现在将DateTime实例转换为Y-m-d格式:


12) The whereDate Method
The query builder's whereDate method now converts DateTime instances to Y-m-d format:

// previous behaviour - SELECT * FROM `table` WHERE `created_at` > '2018-08-01 13:00:00'
$query->whereDate('created_at', '>', Carbon::parse('2018-08-01 13:00:00'));

// current behaviour - SELECT * FROM `table` WHERE `created_at` > '2018-08-01'
$query->whereDate('created_at', '>', Carbon::parse('2018-08-01 13:00:00'));

.
.
.
也可以有更多.这是升级项目时必须要做的事情.请阅读迁移指南

至少,我希望我能给您一个开端.祝你好运!

At least, I hope, I was able to give you a head start. Good Luck!

这篇关于将Laravel 5.0升级到最新版本(7.x)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆