Backend Development 4 min read

How to Build and Publish a Laravel Composer Package from Scratch

This step‑by‑step guide shows how to create a Laravel 5.6 project, develop a reusable Composer package with routing and permission features, test it locally, and finally publish it on GitHub and Packagist for easy installation via Composer.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
How to Build and Publish a Laravel Composer Package from Scratch

Tools and Materials

git

composer

IDE

Preparation

Create a blank Laravel 5.6 project:

composer create-project laravel/laravel laraveltest --prefer-dist

Configure the .env file and database settings.

Create a folder in the project root to hold the package resources.

Package Development Process

Develop the package in a separate project (e.g., a routing and permission validation package) and implement the desired functionality.

Copy the developed file structure into the custom folder of the blank Laravel project (e.g., project_root/dongdong/routeauth ).

Create a src directory and add a ServiceProvider.

In the provider implement two methods: register : bind services into the container. boot : publish assets using publishes . Running php artisan vendor:publish --force copies files to the target folder and overwrites existing ones.

Run composer init in the package folder to generate composer.json , then remove the "type": "project" entry.

Local Testing

Modify the main Laravel project's composer.json to point to the local package directory.

Run composer update , then publish with php artisan vendor:publish --force .

Publishing to Packagist

Create a GitHub repository (e.g., https://github.com/dongdonggo/routeAuth ) and push the package files.

Sign up on Packagist and submit the GitHub repository URL.

After approval, the package can be required with composer require vendor/route-auth . If you previously used a Chinese mirror, switch back to the main Packagist URL before requiring.

backendOpen SourcePHPComposerLaravelPackage Development
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.