laravel UnexpectedValueException 尝试安装 laravelcollective 时无法解析版本约束

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

UnexpectedValueException Could not parse version constraint when trying to instal laravelcollective

phplaravellaravel-5composer-phplaravelcollective

提问by incense_stick

I am new to laravel and I am trying to install laravelcollective. I am just following to documentation hereand I am using this from my project directory:

我是 laravel 的新手,我正在尝试安装laravelcollective。我只是按照这里的文档,我从我的项目目录中使用它:

composer require "laravelcollective/html":"^5.4.0"

composer require "laravelcollective/html":"^5.4.0"

Unfortunately, immediately after I press ented I get the following error :

不幸的是,在我按下 ent 后立即出现以下错误:

[UnexpectedValueException] Could not parse version constraint :5.4.0: Invalid version string ":5.4.0"

[UnexpectedValueException] 无法解析版本约束:5.4.0:版本字符串“:5.4.0”无效

I just don't know how to troubleshoot this. I didn't find much on google and this combined with my lack of experience with laravel leaves me stuck.

我只是不知道如何解决这个问题。我在谷歌上没有找到太多东西,再加上我对 Laravel 缺乏经验,这让我陷入困境。

Can someone help?

有人可以帮忙吗?

采纳答案by Thomas Rollet

You can add it manually in composer.jsonthen use composer update.

您可以手动添加它,composer.json然后使用composer update.

Just add "laravelcollective/html": "5.4.*",under the row with "laravel/framework":"5.4.*",

只需"laravelcollective/html": "5.4.*",在行下添加"laravel/framework":"5.4.*",

Like this :

像这样 :

"require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "laravel/framework": "5.4.*",
        "laravelcollective/html": "5.4.*", <-- Add this row
        "laravel/tinker": "~1.0"
    },

回答by xabbuh

You should never run composer updatewithout any arguments if you do not want to update allyour dependencies.

composer update如果您不想更新所有依赖项,则永远不应在没有任何参数的情况下运行。

In your case, the issue probably is that the ^character is already interpreted by your shell before the argument is passed to Composer. This could possibly be solved by using single quotes instead of double quotes:

在您的情况下,问题可能是^在将参数传递给 Composer 之前,您的 shell 已经解释了该字符。这可以通过使用单引号而不是双引号来解决:

composer require 'laravelcollective/html:^5.4.0'

When you used the 5.4.*constraint as suggested in one of the comments above, you added a space after the colon which leads to Composer interpreting the version constraint as a package name. The right command would have been this:

当您5.4.*按照上述评论之一的建议使用约束时,您在冒号后添加了一个空格,这会导致 Composer 将版本约束解释为包名称。正确的命令是这样的:

composer require "laravelcollective/html":"5.4.*"

回答by Bla Bla

composer require "laravelcollective/html ^5.4.0"

Worked for me!

对我来说有效!

回答by mikejay

In my case, I was using Laravel 5.7 and kept getting an error when trying to install the Laravel collective.

就我而言,我使用的是 Laravel 5.7,并在尝试安装 Laravel 集合时不断收到错误消息。

You can use this command without specifying any version:

您可以在不指定任何版本的情况下使用此命令:

composer require 'laravelcollective/html'

It worked for me. :)

它对我有用。:)