laravel 5.2:未定义命令“优化”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44625918/
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 16:10:18  来源:igfitidea点击:

laravel 5.2: Command "optimize" is not defined

phplaravellaravel-5

提问by Maahi Negi

I am working on laravel 5.2.

我正在研究 Laravel 5.2。

When I run composer install and composer update command, it show error:

当我运行 composer install 和 composer update 命令时,它显示错误:

[InvalidArgumentException] Command "optimize" is not defined.

Please let me know how to solved this problem.

请让我知道如何解决这个问题。

回答by JoeGalind

This artisan command is deprecated. Simply remove it from your composer.json file.

此工匠命令已弃用。只需从您的 composer.json 文件中删除它。

回答by Muhammad Sulman

"scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate",
            "php artisan jwt:secret -f"
        ],
        "post-install-cmd": [
            "Illuminate\Foundation\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\Foundation\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },

remove php artisan optimizefrom post-install-cmdarray and also from post-update-cmdthan it will look like this.

php artisan optimizepost-install-cmd数组中删除,也从post-update-cmd比它看起来像这样。

"scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate",
            "php artisan jwt:secret -f"
        ],
        "post-install-cmd": [
            "Illuminate\Foundation\ComposerScripts::postInstall",
        ],
        "post-update-cmd": [
            "Illuminate\Foundation\ComposerScripts::postUpdate",
        ]
    },

working perfectly fine without any warning.

工作得很好,没有任何警告。

回答by Ryan

https://laravel.com/docs/5.6/upgradesays:

https://laravel.com/docs/5.6/upgrade说:

The previously deprecated optimizeArtisan command has been removed. With recent improvements to PHP itself including the OPcache, the optimizecommand no longer provides any relevant performance benefit. Therefore, you may remove php artisan optimizefrom the scriptswithin your composer.jsonfile.

以前不推荐使用的optimizeArtisan 命令已被删除。随着最近对 PHP 本身的改进,包括 OPcache,该 optimize命令不再提供任何相关的性能优势。因此,你可能会删除 php artisan optimizescripts您的内部composer.json文件。

回答by Krishnamoorthy Acharya

Please note the after install or upgrade laravel following commands will be executed through composer.json file. Since 5.2 onwards optimize command has been depreciated. Please remove it.enter image description here

请注意,在安装或升级 laravel 后,以下命令将通过 composer.json 文件执行。从 5.2 开始,优化命令已贬值。请删除它。在此处输入图片说明

回答by Amitesh

To add of other accepted answer posted :

添加其他已接受的答案:

I face this error while migrating project from laravel5.2 to laravel5.6

我在将项目从 laravel5.2 迁移到 laravel5.6 时遇到了这个错误

Made following change in the composer.json

在 composer.json 中进行了以下更改

  • Ensure "post-create-project-cmd" of "Scripts" doesn't have "Illuminate\Foundation\ComposerScripts::postInstall", "php artisan optimize" line

  • Ensure "post-update-cmd" of "Scripts" doesn't have
    "Illuminate\Foundation\ComposerScripts::postUpdate", "php artisan optimize" line

  • 确保“脚本”的“post-create-project-cmd”没有“Illuminate\Foundation\ComposerScripts::postInstall”、“php artisan optimize”行

  • 确保“脚本”的“post-update-cmd”没有
    “Illuminate\Foundation\ComposerScripts::postUpdate”、“php artisan optimize”行

** Still project didn't run**

** 仍然项目没有运行**

Log file shows "Please provide a valid cache path" error. Run following command from project root and it worked.

日志文件显示“请提供有效的缓存路径”错误。从项目根目录运行以下命令,它工作正常。

 mkdir -p storage/framework/{sessions,views,cache}