Packages2 min read

Build your first Laravel package

A package is a folder with a composer.json and one class Laravel calls. This series builds a small, useful one from an empty folder to a tagged release, one part at a time.

By Abhishek Fouzdar · Updated

Every Laravel app I have worked on grew the same handful of helpers: a settings table with a class around it, a few custom validation rules, an Artisan command that cleans up something. Then the next project started, and someone copied those files across, and the two copies drifted apart. A package is how you stop doing that. You write the code once, give it a name, and every project installs the same thing.

Updated 24 October 2026: the example package now supports Laravel 13 as well as 12 (v0.2.0, one extra commit after the four parts), and the version constraints in the parts were updated to match. Everything else is as first published.

Packages have a reputation for being advanced. They are not. A Laravel package is a folder with a composer.json in it and one class that tells Laravel the folder exists. Everything else is ordinary Laravel: a migration, a model, a class, a config file. The only new material is the wiring, and this series walks through all of it in order.

What you will build

A small package called laravel-settings. It stores application settings in a database table, the values someone wants to change without a deploy: the site name, a support address, whether registration is open. It reads them through a facade, so using it looks like Laravel:

use Shipbytes\Settings\Facades\Settings;

Settings::set('registration_open', false);

if (Settings::get('registration_open', true)) {
    // show the sign-up form
}

Behind that facade sit a migration, a model, a class that reads the whole table once and caches it, and a config file you can publish. None of it is hard. That is deliberate: the feature stays small so your attention can go to the packaging.

The finished package is on GitHub at shipbytes/laravel-settings. Each part of this series is one commit there, so when something on your machine does not match, you can diff against the commit for that part.

What you need

  • PHP 8.2 or newer and Composer. Check with php -v and composer -V.
  • A Laravel 12 or 13 application to test the package in. A fresh one is best: composer create-project laravel/laravel settings-app, which today gives you Laravel 13.
  • A terminal and an editor. No Docker, no database server: the tests use an in-memory SQLite database, and the test app can use SQLite too.

You do not need to have written a package before. You do need to be comfortable with the basics of a Laravel app: what a migration is, what a service provider does at a high level, how to run Artisan commands.

The parts

  1. A package is just a folder. The folder, composer.json, PSR-4 autoloading, the service provider and auto-discovery. You install the empty package into your app and watch Laravel find it.
  2. The settings feature. The migration, the model, the Settings class with its one cached read, and the facade. You use it from a route.
  3. Testing without an app. Orchestra Testbench boots a bare Laravel just for your tests. You write tests for the defaults, the types and the cache, then add Pint and PHPStan.
  4. Sharing it. GitHub Actions runs your tests on every push, you write a README someone can follow, and you tag a first version. Publishing to Packagist is explained but left to you.

Each part ends with a checkpoint: what should exist, what command should print what, and the commit to compare against. If you get stuck, the diff is the fastest way out.

Start with part 1.

New posts by email

Get new posts by email. Nothing else, no digests, unsubscribe in one click.

Comments

Comments are GitHub Discussions in shipbytes/discussions. Sign in with GitHub to post.