John
John

Reputation: 21

Install Custom laravel Package

I have created custom basic Laravel package and i have uploaded it on my github account and also connected github repo to https://packagist.org .

My repository url is https://github.com/johnsmithamk/message.git

I want to install that package from github to new Laravel application on my local server.

I am using Laravel verson 5.5. Below is my composer.json code

Composer.json

 {

 "name": "johnsmithamk/message",

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

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

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

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

}

After adding repository to Packagist it tells to use this command to install the packages:

composer create-project johnsmithamk/message

but after running above command i am getting following errors:

[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>]

Could anyone suggest on how to install laravel package from github?

Please check the composer.json code and let me know whether i have made some mistakes or not.

Upvotes: 2

Views: 2702

Answers (1)

PaladiN
PaladiN

Reputation: 4944

You need to use

composer require johnsmithamk/message

instead of

composer create-project johnsmithamk/message

I have tested your repository to install into my project and it is not showing any of the issue you have mentioned.

require includes the package into your already existing project and create-project creates a new project as it says.

You could have a look on their differences:

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

Edit:

Added your package to the project and got some error but that is due to your some codes in your composer.json like:

1.Need to remove this vcs type from the composer.json as we will use packagist.

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

Have a look on some popular package's composer.json

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

2.Uses the dev only and not master branch as there might be only dev branch for now but need to have a look on this.

"minimum-stability": "dev",

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

My log doesn't show any error.

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.

Upvotes: 1

Related Questions