Search code examples
phplaravelcomposer-phplaravel-sail

How to use local packages in Laravel Sail


I'm building at the moment a new Laravel Package on my local machine. I also have a local project with Laravel Sail to test the new package.

** Laravel Sail composer.json **

"repositories": {
        "local": {
            "type": "path",
            "url": "../packages/new-package"
        }
    }

Now when I try the command sail composer require vendor/new-package, I get the error: The url supplied for the path (../packages/new-package) repository does not exist.

I know my Sail App is in a Docker container and the path ../packages/new-package can not exist there. But how can I fix this, how can I use a local packge in a Laravel Sail Application?


Solution

  • By default when using Sail only the project directory is mounted in the Sail container as a volume.

    You can customise your sail compose file by running:

    sail artisan sail:publish
    

    This should publish the default Sail docker-compose.yml file in the project root directory to allow you to modify it.

    In order to allow composer to load packages from local path repositories you can mount the path in the exact same relative location in the container. This may look like something like below:

    volumes:
      # Default one
      - '.:/var/www/html'
      # New one
      - ../packages:/var/www/packages