Using a private Composer package with Laravel.

Categories: Development

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": "",
    "support": {
        "issues": "",
        "source": ""
    "autoload": {
        "psr-4": {
            "AdamPatterson\\Core\\": "src/"
        "files": [
    "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 someKindOfKeyHere

Otherwise, your builds will fail.

Adam Patterson

Adam Patterson

User Interface Designer & Developer with a background in UX. I have spent 5 years as a professionally certified bicycle mechanic and ride year-round.

I am a husband and father of two, I enjoy photography, music, movies, coffee, and good food.

You can find me on Twitter, Instagram, and YouTube!