将 Laravel 5.4 升级到最新版本 (5.7)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52849408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:07:06  来源:igfitidea点击:

Upgrading Laravel 5.4 to latest version (5.7)

phplaravellaravel-upgrade

提问by Michael

I am working on Laravel 5.4 with PHP version 5.6.4. My goal is to upgrade my project to Laravel 5.7 with PHP 7.1.

我正在使用 PHP 5.6.4 版开发 Laravel 5.4。我的目标是使用 PHP 7.1 将我的项目升级到 Laravel 5.7。

Now my question is: Do I have to upgrade to 5.5 > 5.6 > 5.7 or can I go directly from 5.4 to 5.7?

现在我的问题是:我必须升级到 5.5 > 5.6 > 5.7 还是可以直接从 5.4 升级到 5.7?

回答by Гордей Петрович

There are some articles on documentation. You can upgrade to 5.7 directly but be sure to modify critical sections from this links 5.5->5.6, 5.6->5.7. And make a backup of current project first

有一些关于文档的文章。您可以直接升级到 5.7,但一定要从这个链接5.5->5.6, 5.6->5.7修改关键部分。并先备份当前项目

回答by Karthik Sekar

Better to upgrade 5.5 first an then go with 5.6 and 5.7 because if you see in 5.5 and 5.6 upgrade guide there are some packages also need to upgrade so you better go with the step by step.

最好先升级 5.5,然后再升级 5.6 和 5.7,因为如果您在 5.5 和 5.6 升级指南中看到有一些软件包也需要升级,所以您最好逐步进行。

For older versions, you can look at

对于旧版本,您可以查看

回答by Nico Haase

From my point of view, it would help to upgrade step by step. This helps to to see whether your application is already compatible with all changes that need to be made.

在我看来,逐步升级会有所帮助。这有助于查看您的应用程序是否已经与所有需要进行的更改兼容。

If you upgrade to 5.7 directly and face larger problems due to the changes, your quickest option is to downgrade to 5.4 again.

如果您直接升级到 5.7 并且由于更改而面临更大的问题,您最快的选择是再次降级到 5.4。

If you upgrade to 5.5 in the first step, you can make your application compatible to 5.5, test it thoroughly, deploy it, and start to test what needs to be done for the upgrade to 5.6.

如果你在第一步升级到 5.5,你可以让你的应用程序兼容 5.5,彻底测试它,部署它,然后开始测试升级到 5.6 需要做什么。

回答by Smit Patel

For updating Laravel 6.x (Which means any subversions to V6)
Just run this command

要更新 Laravel 6.x(这意味着对 V6 的任何颠覆)
只需运行此命令

cd [laravel installation directory]
composer update

cd [laravel installation directory]
composer update

You must have composer installed on your VM or PC.

您必须在 VM 或 PC 上安装 Composer。

For Linux users only:

仅适用于 Linux 用户:

Composer directory must be owned by current user

Composer 目录必须归当前用户所有

//Check ownership
ls -la ~/ | grep ".composer"

//If you don't own the directory
chown -R [user]/[user] ~/.composer

Message me on any social media @smitpatelx Or leave a comment if you need any help or if your usecase differ from the above.

在任何社交媒体上给我发消息 @smitpatelx 或者如果您需要任何帮助或者您的用例与上述不同,请发表评论。

回答by Udhav Sarvaiya

Just update your laravel/frameworkdependency to 5.7.*in your composer.jsonfile:

只需在您的文件中更新您的laravel/framework依赖项:5.7.*composer.json

"require": {
    "php": "^7.1.3",
    "fideloper/proxy": "^4.0",
    "laravel/framework": "5.7.*",
    "laravel/tinker": "^1.0"
},

After, run this command on your command prompt: composer update

之后,在命令提示符下运行此命令: composer update

You will achieve success and your Larvael will change to version 5.7, more details are available on upgrade guide

您将获得成功,您的 Larvael 将更改为5.7 版升级指南中提供了更多详细信息

回答by Hamid Naghipour

No,you sholud not upgrade step by step, only you can do this : https://laravel.com/docs/5.7/upgrade

不,你不应该一步一步升级,只有你可以这样做:https: //laravel.com/docs/5.7/upgrade

回答by Tijo Titus

Just update your laravel/framework dependency to 5.7.* in your composer.json file. Since you are upgrading from 5.4 to 5.7, then you can easily just run

只需在您的 composer.json 文件中将您的 laravel/framework 依赖项更新为 5.7.*。既然您是从 5.4 升级到 5.7,那么您可以轻松地运行

composer update

composer update

And if you modified some of Laravel's Traits or Methods in your 5.4 application, then you can check herefor more info

如果您在 5.4 应用程序中修改了 Laravel 的一些特征或方法,那么您可以在此处查看更多信息

回答by Madhuri Patel

You can just update your laravel/framework dependency to 5.7.* in your composer.jsonfile.

您只需将文件中的 laravel/framework 依赖项更新为 5.7.* 即可composer.json

1. change in composer.json:

1. composer.json 的变化:

From:

从:

"require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0"
    },

To:

到:

"require": {
        "php": ">=7.1.3",
        "fideloper/proxy": "~4.0",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "~1.0"
    },

2. Replace app\Http\Middleware\TrustedProxies.php file with contents below:

2. 将 app\Http\Middleware\TrustedProxies.php 文件替换为以下内容:

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array
     */
    protected $proxies;

    /**
     * The headers that should be used to detect proxies.
     *
     * @var string
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}

3. composer update

3.作曲家更新

composer update