安装Custom laravel Package

时间:2017-09-20 04:45:10

标签: laravel

我已创建自定义基本Laravel包,我已将其上传到我的github帐户,并将github repo连接到https://packagist.org

我的存储库网址为https://github.com/johnsmithamk/message.git

我想从github将该软件包安装到我本地服务器上的新Laravel应用程序中。

我正在使用Laravel第5.5节。以下是我的composer.json代码

Composer.json

 {

 "name": "johnsmithamk/message",

"description": "Sample Package in Vendor folder",
"type": "project",
"license": "0.1",
"authors": [
    {
        "name": "John Smith",
        "email": "testing7672@gmail.com"
    }
],
"minimum-stability": "dev",

"require": {
    "Illuminate/support": "~5"
}, 

"autoload":{
    "psr-4":{
        "test\\message\\": "vendor/test/message/src/"
    }
},

"extra": { 
    "laravel": {
        "providers": [
            "test\\message\\MessageServiceProvider"
        ]
    }
} 

}

将存储库添加到 Packagist 后,它会告诉您使用此命令安装软件包:

  

composer create-project johnsmithamk / message

但在执行上述命令后,我遇到以下错误:

[InvalidArgumentException]                                          
  Could not find package johnsmithamk/message with stability stable.  


create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]

有人可以建议如何从github安装laravel包吗?

请检查composer.json代码,告诉我是否犯了错误。

1 个答案:

答案 0 :(得分:1)

您需要使用

  

作曲家需要johnsmithamk / message

而不是

  

composer create-project johnsmithamk / message

我已经测试了您的存储库以安装到我的项目中,但它没有显示您提到的任何问题。

require将软件包包含到您现有的项目中,并create-project创建一个新项目。

你可以看看他们之间的差异:

  

https://stackoverflow.com/a/22944572/3887342

修改

将您的软件包添加到项目中并出现了一些错误,但这是由于您composer.json中的某些代码所致:

1.需要从composer.json中删除此vcs类型,因为我们将使用packagist。

"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/johnsmithamk/message.git"
        }
    ],

看看一些流行的包的composer.json

  

https://github.com/cartalyst/sentinel/blob/2.0/composer.json

2.仅使用dev而不是master分支,因为现在可能只有dev分支,但需要查看它。

"minimum-stability": "dev",
  

https://github.com/LaravelCollective/html/blob/5.5/composer.json#L52

我的日志没有显示任何错误。

C:\xampp\htdocs\Platform>composer require johnsmithamk/message

Using version dev-master for johnsmithamk/message
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing johnsmithamk/message (dev-master 319a00d): Cloning 319a00d01b
    Failed to download johnsmithamk/message from source: Failed to clone https://github.com/johnsmithamk/message.git, git was not found, check that it i
s installed and in your PATH env.

'git' is not recognized as an internal or external command,
operable program or batch file.

    Now trying to download from dist
  - Installing johnsmithamk/message (dev-master 319a00d): Downloading (100%)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize

Generating optimized class loader
The compiled services file has been removed.