Using a private Composer package with Laravel.

Developing packages for use with laravel is reasonably straightforward. But we don’t all make the code for public consumption on Packagist.

Adding a custom repository to your composer.json file will allos us to pull code straight from your Github account rather than Packagist.

repositories": [
    {
      "type": "package",
      "package": {
        "name": "adampatterson/app-core",
        "version": "0.0.4",
        "source": {
          "url": "[email protected]:adampatterson/app-core.git",
          "type": "git",
          "reference": "master"
        }
      }
    }
],

Now you should beable to add your package under require "adampatterson/app-core": "0.0.4"

It’s common practice to palce your source code in a src/ folder. You will also want to create your packages composer.json file with atleast the following details..

{
    "name": "adampatterson/core",
    "description": "Some kind of Core package for an app.",
    "type": "library",
    "homepage": "https://github.com/adampatterson/app-core",
    "support": {
        "issues": "https://github.com/adampatterson/app-core/issues",
        "source": "https://github.com/adampatterson/app-core"
    },
    "autoload": {
        "psr-4": {
            "AdamPatterson\\Core\\": "src/"
        },
        "files": [
            "src/Helpers.php"
        ]
    },
    "authors": [
        {
            "name": "Adam Patterson",
            "email": "[email protected]"
        }
    ]
}

If your package repository is not public you might be asked by Composer to enter an oAuth token. This can be done through a guide on Github.

If you are using Docker or another automated build system you will want to add the following to your build script.

RUN /usr/local/bin/composer config -g github-oauth.github.com someKindOfKeyHere

Otherwise your builds will fail.



Signup for my mailing list

Receive other rambings like this on design, code, and some times food.