Laravel在自己的项目中使用包

时间:2017-09-22 18:10:31

标签: php laravel composer-php

我正在Laravel 5.5建立一个包。现在我想使用那个包 在我自己的项目中本地。

我的包中的composer.json看起来像这样:

{
    "name": "larsjanssen6/underconstruction",
    "license": "MIT",
    "homepage": "https://github.com/larsjanssen6/underconstruction",
    "authors": [
        {
            "name": "Lars Janssen",
            "email": "larsjanssen64@gmail.com",
            "role": "Developer"
        }
    ],
    "require": {
        "php" : "^7.0",
        "illuminate/support": "~5.5.0"
    },
    "autoload": {
        "psr-4": {
            "LarsJanssen\\underconstruction\\": "src/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "extra": {
        "laravel": {
            "providers": [
                "LarsJanssen\\underconstruction\\UnderConstructionServiceProvider"
            ]
        }
    }
}

https://github.com/larsjanssen6/underconstruction

在一个新的laravel项目中,我在composer.json文件中添加了这样的包:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/larsjanssen6/underconstruction"
        }
    ],
    "require": {
        "php": ">=7.0.0",
        "fideloper/proxy": "~3.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "larsjanssen6/underconstruction": "master"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~6.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}

但是我收到了这个错误:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package larsjanssen6/underconstruction could not be found in any version, there may be a typo in the package name.

这里可能有什么问题?

1 个答案:

答案 0 :(得分:2)

从评论部分移动答案。

您需要dev-master才能获得master's branch code

如果您有某种其他分支,请说second-branch,您可以在 composer.json 文件中使用dev-second-branch

...
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/larsjanssen6/underconstruction"
    }
],
"require": {
    ...
    "larsjanssen6/underconstruction": "dev-master"
},
...