如何将laravel/laravel从5.3更新到5.4?

3

我尝试将laravel/laravel5.3更新到5.4,为此,我已经修改了composer.json文件如下:

 {
        "name" : "laravel/laravel",
        "description" : "The Laravel Framework.",
        "keywords" : [
            "framework",
            "laravel"
        ],
        "license" : "MIT",
        "type" : "project",
        "require" : {
            "php" : ">=5.6.4",
            "laravel/framework" : "5.4.*",
            "h4cc/wkhtmltopdf-amd64" : "0.12.x",
            "h4cc/wkhtmltoimage-amd64" : "0.12.x",
            "barryvdh/laravel-snappy" : "^0.3.3",
            "greggilbert/recaptcha" : "dev-master"
        },
        "require-dev" : {
            "fzaninotto/faker" : "~1.4",
            "mockery/mockery" : "0.9.*",
            "phpunit/phpunit" : "~5.7",
            "symfony/css-selector" : "2.8.*|3.0.*",
            "symfony/dom-crawler" : "2.8.*|3.0.*",
            "barryvdh/laravel-ide-helper" : "^2.2",
            "guzzlehttp/guzzle" : "~6.0"
        },
        "autoload" : {
            "classmap" : [
                "database"
            ],
            "psr-4" : {
                "App\\" : "app/"
            }
        },
        "autoload-dev" : {
            "classmap" : [
                "tests/TestCase.php"
            ]
        },
        "scripts" : {
            "post-root-package-install" : "php -r \"copy('.env.example', '.env');\"",
            "post-create-project-cmd" : "php artisan key:generate",
            "post-install-cmd" : [
                "Illuminate\\Foundation\\ComposerScripts::postInstall",
                "php artisan optimize"
            ],
            "post-update-cmd" : [
                "Illuminate\\Foundation\\ComposerScripts::postUpdate",
                "php artisan optimize"
            ]
        },
        "config" : {
            "preferred-install" : "dist"
        }
    }

然后我运行了

$ composer update

看起来 composer 没有做任何事情:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 0 updates, 0 removals
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled class file has been removed.

当我运行时

$ php artisan --version

输出结果为:

Laravel Framework version 5.3.31

composer.lock 中,我找到了这个:
    {
        "name": "laravel/framework",
        "version": "v5.3.31",
        "source": {
            "type": "git",
            "url": "https://github.com/laravel/framework.git",
            "reference": "e641e75fc5b26ad0ba8c19b7e83b08cad1d03b89"
        },
        "dist": {
            "type": "zip",
            "url": "https://api.github.com/repos/laravel/framework/zipball/e641e75fc5b26ad0ba8c19b7e83b08cad1d03b89",
            "reference": "e641e75fc5b26ad0ba8c19b7e83b08cad1d03b89",
            "shasum": ""
        },
        "require": {
            "classpreloader/classpreloader": "~3.0",
            "doctrine/inflector": "~1.0",
            "ext-mbstring": "*",
            "ext-openssl": "*",
            "jeremeamia/superclosure": "~2.2",
            "league/flysystem": "~1.0",
            "monolog/monolog": "~1.11",
            "mtdowling/cron-expression": "~1.0",
            "nesbot/carbon": "~1.20",
            "paragonie/random_compat": "~1.4|~2.0",
            "php": ">=5.6.4",
            "psy/psysh": "0.7.*|0.8.*",
            "ramsey/uuid": "~3.0",
            "swiftmailer/swiftmailer": "~5.4",
            "symfony/console": "3.1.*",
            "symfony/debug": "3.1.*",
            "symfony/finder": "3.1.*",
            "symfony/http-foundation": "3.1.*",
            "symfony/http-kernel": "3.1.*",
            "symfony/process": "3.1.*",
            "symfony/routing": "3.1.*",
            "symfony/translation": "3.1.*",
            "symfony/var-dumper": "3.1.*",
            "vlucas/phpdotenv": "~2.2"
        },
        "replace": {
            "illuminate/auth": "self.version",
            "illuminate/broadcasting": "self.version",
            "illuminate/bus": "self.version",
            "illuminate/cache": "self.version",
            "illuminate/config": "self.version",
            "illuminate/console": "self.version",
            "illuminate/container": "self.version",
            "illuminate/contracts": "self.version",
            "illuminate/cookie": "self.version",
            "illuminate/database": "self.version",
            "illuminate/encryption": "self.version",
            "illuminate/events": "self.version",
            "illuminate/exception": "self.version",
            "illuminate/filesystem": "self.version",
            "illuminate/hashing": "self.version",
            "illuminate/http": "self.version",
            "illuminate/log": "self.version",
            "illuminate/mail": "self.version",
            "illuminate/notifications": "self.version",
            "illuminate/pagination": "self.version",
            "illuminate/pipeline": "self.version",
            "illuminate/queue": "self.version",
            "illuminate/redis": "self.version",
            "illuminate/routing": "self.version",
            "illuminate/session": "self.version",
            "illuminate/support": "self.version",
            "illuminate/translation": "self.version",
            "illuminate/validation": "self.version",
            "illuminate/view": "self.version",
            "tightenco/collect": "self.version"
        },
        "require-dev": {
            "aws/aws-sdk-php": "~3.0",
            "mockery/mockery": "~0.9.4",
            "pda/pheanstalk": "~3.0",
            "phpunit/phpunit": "~5.4",
            "predis/predis": "~1.0",
            "symfony/css-selector": "3.1.*",
            "symfony/dom-crawler": "3.1.*"
        },
        "suggest": {
            "aws/aws-sdk-php": "Required to use the SQS queue driver and SES mail driver (~3.0).",
            "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).",
            "fzaninotto/faker": "Required to use the eloquent factory builder (~1.4).",
            "guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (~5.3|~6.0).",
            "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (~1.0).",
            "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (~1.0).",
            "pda/pheanstalk": "Required to use the beanstalk queue driver (~3.0).",
            "predis/predis": "Required to use the redis cache and queue drivers (~1.0).",
            "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (~2.0).",
            "symfony/css-selector": "Required to use some of the crawler integration testing tools (3.1.*).",
            "symfony/dom-crawler": "Required to use most of the crawler integration testing tools (3.1.*).",
            "symfony/psr-http-message-bridge": "Required to use psr7 bridging features (0.2.*)."
        },
        "type": "library",
        "extra": {
            "branch-alias": {
                "dev-master": "5.3-dev"
            }
        },

出了什么问题?

提前感谢任何帮助。


你使用的是哪个 PHP 版本? - Niklesh Raut
1
在运行 composer update 命令之前,请尝试运行 composer install 命令,如果仍然无法解决问题,只需删除 vendor 目录并重新执行命令即可。 - apokryfos
Php 版本:5.6.30 - ratm
Composer安装不会破坏项目吗? - ratm
注意:仅仅更新Composer依赖项并不能升级您的Laravel应用程序到新版本。根据升级指南列出的步骤,还需要进行数十个额外的步骤。如果您选择使用Laravel Shift自动化升级,则可以简化这些步骤。 - Jason McCreary
6个回答

2

不要编辑composer.json,尝试运行以下命令:

composer require laravel/laravel:^5.4.0 --update-with-dependencies

参考文献,请参阅https://getcomposer.org/doc/03-cli.md#require.

--update-with-dependencies:同时更新新添加的包的依赖。

注意:很少有理由手动修改composer.json文件,尤其是在相应的命令可用时。


composer.json 不是圣杯。可以安全地编辑该文件并发出 composer 命令以在更改后重新处理它。 - Marcin Orlowski
取决于a)你具体从事什么工作,以及b)你对“安全”的理解。 - localheinz
@ratm 你能把它分享到问题中吗? - localheinz
@ratm 你能运行 composer —version 并分享结果吗? - localheinz
Composer版本:1.5.2。我使用Docker。 - ratm

1

它可以与以下内容一起使用:

composer require laravel/framework:^5.4.0 --update-with-dependencies

0

它不起作用,但有错误日志:

 composer require laravel/laravel:^5.4.0 --update-with-dependencies
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package laravel/laravel No version set (parsed as 1.0.0) is satisfiable by laravel/laravel[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.
  Problem 2
    - laravel/laravel v5.5.0 requires php >=7.0.0 -> your PHP version (5.6.30) does not satisfy that requirement.
    - laravel/laravel v5.4.9 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.30 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.3 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.23 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.21 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.19 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.16 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.15 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - laravel/laravel v5.4.0 requires laravel/framework 5.4.* -> satisfiable by laravel/framework[5.4.x-dev, v5.4.0, v5.4.1, v5.4.10, v5.4.11, v5.4.12, v5.4.13, v5.4.14, v5.4.15, v5.4.16, v5.4.17, v5.4.18, v5.4.19, v5.4.2, v5.4.20, v5.4.21, v5.4.22, v5.4.23, v5.4.24, v5.4.25, v5.4.26, v5.4.27, v5.4.28, v5.4.29, v5.4.3, v5.4.30, v5.4.31, v5.4.32, v5.4.33, v5.4.34, v5.4.35, v5.4.36, v5.4.4, v5.4.5, v5.4.6, v5.4.7, v5.4.8, v5.4.9] but these conflict with your requirements or minimum-stability.
    - Installation request for laravel/laravel ^5.4.0 -> satisfiable by laravel/laravel[v5.4.0, v5.4.15, v5.4.16, v5.4.19, v5.4.21, v5.4.23, v5.4.3, v5.4.30, v5.4.9, v5.5.0].

0

如果想要将Laravel 5.3升级到Laravel 5.4

你需要将laravel/framework: 5.3.*更改为5.4.*

你需要将phpunit/phpunit: ~5.7更改为相应版本

你需要将"laravelcollective/html": "^5.4.0"更改为相应版本

然后在终端中运行composer update

如果存在,可以删除bootstrap/cache/compiled.php文件。该文件不再被框架使用。

在升级所有包之后,您应该运行php artisan view:clear以避免与Illuminate\View\Factory::getFirstLoop()相关的Blade错误。此外,您可能需要运行php artisan route:clear来刷新路由缓存。


0

我通过编辑一些文件中的一些小改动,将 Laravel 项目从5.3转换为5.4。


请详细说明您在哪些文件中进行了哪些更改。 - contradictioned

0

只需执行

composer update laravel/framework --with-all-dependencies


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接