opensourceprojects.dev

A broadsheet for software that doesn't ask for your email

Multi-tenancy for Laravel that doesn't touch your app code
GitHub RepoViews6

Project Description

View on GitHub

Multi-Tenancy for Laravel Without Rewriting Your App

You've got a Laravel app that works. Now you need it to serve multiple tenants, each with their own data, and every tutorial you find starts with "first, go through your models and add a trait." That's the moment most people close the tab. Tenancy for Laravel (the stancl/tenancy package) takes a different approach—the pitch is that you won't have to change a thing in your application's code.

What It Does

Tenancy for Laravel is a package that adds automatic multi-tenancy to a Laravel application. The core idea is that your existing app code keeps working as-is: no model traits to swap database connections, and no replacing Laravel's built-in classes like Cache or Storage with tenancy-aware versions. The package handles the tenant context for you rather than asking you to thread it through your codebase.

The README also highlights built-in tenant identification based on hostname, including support for second-level domains. So instead of building your own middleware to figure out which tenant a request belongs to, that identification is part of what the package provides. It targets Laravel 10.x according to the version badge, and the project is maintained by Samuel Štancl, with documentation hosted at tenancyforlaravel.com.

Why It's Cool

It respects your existing code. The most interesting thing here isn't a feature list—it's a design constraint. Multi-tenancy packages often force invasive changes: traits on every model, swapped service providers, custom facades. This one is built around the promise that you don't touch your application code. That means adopting it doesn't turn into a refactor project.

  • No model traits for database connections. If you've looked at other tenancy solutions, you know the drill—every model gets a trait so it knows which database to talk to. Here, that's explicitly not required.
  • No shadow versions of Laravel classes. You keep using Cache and Storage as you normally would. The package doesn't ask you to mentally track which variant of a class you're calling in which part of your app.
  • Hostname-based identification is built in. Tenant resolution by hostname—including second-level domains—ships with the package. That's one less piece of infrastructure you have to design and maintain yourself.

The combination matters because multi-tenancy is one of those problems where the "simple" solution (a tenant_id column everywhere) and the "proper" solution (separate databases per tenant) both have real costs. A package that abstracts the tenant context away from your code, rather than into it, keeps those costs from leaking into every file you write.

How to Try It

The README points you straight at the documentation, which is where you'll want to start—the setup steps live there rather than in the README itself.

  1. Head to the docs at v4.tenancyforlaravel.com and follow the installation guide for your Laravel version.
  2. The package is distributed via Composer, so you'll pull it in the usual way (check the docs for the current package name and version constraint).
  3. Configure your tenant identification—hostname-based identification, including second-level domains, is built in, so you can start there.
  4. If you get stuck, there's a support guide linked from the repo.

The repository is at github.com/archtechx/tenancy—star it, read the docs, and see whether the "no code changes" claim holds up against your app. If you're weighing tenancy approaches, that claim is the thing worth testing first.

Final Thoughts

This is a focused package with a clear thesis: multi-tenancy shouldn't require you to rewrite your application. If you're running a Laravel app that needs to serve multiple tenants and you've been putting it off because every option looked invasive, this is worth an afternoon of reading the docs. It won't be the right fit for every architecture—no package is—but the design philosophy alone makes it a useful reference point when you're comparing your options. Give the documentation a read before you commit; the README is honest about being a signpost rather than a manual.


Follow @githubprojects for more developer tools and open source projects.

Back to Projects
Project ID: tenancyLast updated: December 4, 2026 at 02:49 AM