DEV Community

Orfeo
Orfeo

Posted on

Add composer package using path for development

Testing a Local Laravel Package with Composer Path Repositories

When developing a custom Laravel package, you might want to test it inside another Laravel project without publishing it to Packagist. Composer allows this with the path repository type, which creates a symlink to your package instead of copying it.

This way, any changes you make to the package’s files are instantly available in your testing project.


1. Add the Local Package Repository

In your Laravel project (the consumer project), tell Composer where your local package is located.

Run:

composer config repositories.local '{"type": "path", "url": "/absolute/path/to/my-dev-package"}' --file composer.json
Enter fullscreen mode Exit fullscreen mode
  • Replace /absolute/path/to/my-dev-package with the full path to your package’s root folder.
  • This adds a repositories entry to your composer.json for the given path.

2. Require the Package

Install your package into the consumer project:

composer require my/dev-package
Enter fullscreen mode Exit fullscreen mode
  • Use the same name defined in your package’s composer.json under "name": "my/dev-package".
  • Composer will create a symlink so changes in your package source are reflected immediately.

3. Work on the Package in Real Time

Since this is a symlink, you can:

  • Edit files in /absolute/path/to/my-dev-package
  • Refresh or run your Laravel project
  • See changes instantly without reinstalling the package

4. Optional: Use “version” for Better Control

If your package composer.json contains a "version" key (e.g., "version": "1.0.0") or uses a dev-branch version, Composer can handle updates more gracefully.

Example for a development branch:

"version": "dev-main"
Enter fullscreen mode Exit fullscreen mode

Then require:

composer require my/dev-package:dev-main
Enter fullscreen mode Exit fullscreen mode

5. When Ready to Publish

Once your package is stable, you can:

  • Remove the path repository from composer.json
  • Require it from Packagist or your private VCS repository

Top comments (0)