Building a Laravel Package: Providers &amp; Config | Mohamed Said       [Skip to content](#main)  [ ![](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png) Mohamed SaidLaravel Backend Engineer ](https://www.msaied.com/public) - [Home](https://www.msaied.com/public)
- [Projects](https://www.msaied.com/public/projects)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [About](https://www.msaied.com/public#about)

           [  Contact](https://www.msaied.com/public#contact) Menu 

Menu
----

Close 

 - [HomeStart here](https://www.msaied.com/public)
- [ProjectsCase studies](https://www.msaied.com/public/projects)
- [ArticlesEngineering notes](https://www.msaied.com/public/articles)
- [CertificatesCredentials](https://www.msaied.com/public/certificates)
- [AboutHow I work](https://www.msaied.com/public#about)
- [ContactGet in touch](https://www.msaied.com/public#contact)

  [Start a conversation](https://www.msaied.com/public#contact) [WhatsApp](https://wa.me/201094619204) [Email](mailto:hello@msaied.com) 

 1. [Home](https://www.msaied.com/public)
2. /
3. [Articles](https://www.msaied.com/public/articles)
4. /
5. Building a Laravel Package: Service Providers, Auto-Discovery, and Config Merging

 Building a Laravel Package: Service Providers, Auto-Discovery, and Config Merging
==================================================================================

 Learn how to build a production-ready Laravel package from scratch — covering service provider design, auto-discovery, config merging, and the subtle pitfalls that trip up even experienced package authors.

 ![](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp) [Mohamed Said](https://www.msaied.com/public#person) Published 21 Sep 2026 · Updated 21 Sep 2026 · 1 min read

ShareCopy linkCopied

 ![Building a Laravel Package: Service Providers, Auto-Discovery, and Config Merging](https://cdn.msaied.com/687/e53f819c8f897c1ad12a1df0661a18f7.png) 

  On this page +1. [Why Package Architecture Matters](#why-package-architecture-matters)
2. [Structuring the Service Provider](#structuring-the-service-provider)
3. [The register vs boot Distinction](#the-coderegistercode-vs-codebootcode-distinction)
4. [Auto-Discovery via Composer](#auto-discovery-via-composer)
5. [Config Merging: The Subtle Trap](#config-merging-the-subtle-trap)
6. [Deferring Expensive Bindings](#deferring-expensive-bindings)
7. [Testing Your Package in Isolation](#testing-your-package-in-isolation)
8. [Key Takeaways](#key-takeaways)

 Why Package Architecture Matters
--------------------------------

Most Laravel developers have consumed dozens of packages but never authored one. When you finally do, the gap between "it works locally" and "it works reliably for everyone" turns out to be surprisingly wide. This article focuses on the three pillars that determine package quality: service provider design, Composer auto-discovery, and config merging — with real code and the edge cases that documentation glosses over.

---

Structuring the Service Provider
--------------------------------

Your service provider is the package's public API to the framework. Keep it thin: register bindings, merge config, load routes/views, and declare publishables. Avoid business logic here.

```php
