PHPackages                             asseco-voice/laravel-multitenancy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. asseco-voice/laravel-multitenancy

ActiveLibrary[Database &amp; ORM](/categories/database)

asseco-voice/laravel-multitenancy
=================================

Laravel multitenancy support

v1.0.0(4y ago)2101MITPHPPHP ^8.0CI failing

Since May 5Pushed 1y ago6 watchersCompare

[ Source](https://github.com/asseco-voice/laravel-multitenancy)[ Packagist](https://packagist.org/packages/asseco-voice/laravel-multitenancy)[ RSS](/packages/asseco-voice-laravel-multitenancy/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (3)Used By (0)

[![](https://github.com/asseco-voice/art/raw/main/evil_logo.png)](https://see.asseco.com)

Multitenancy
============

[](#multitenancy)

Purpose of this repository is to enable multitenancy with multiple DB setup.

Installation
============

[](#installation)

Require the package with `composer require asseco-voice/laravel-multitenancy`. Service provider will be registered automatically.

Setup
=====

[](#setup)

DB setup
--------

[](#db-setup)

Since this is a multi-DB tenancy package be sure to provide separate env values for landlord connection as well as connection for tenants.

Landlord is a separate DB connection which holds all shared migrations. The main one given through the package is `tenants` table which will hold configuration for all the tenants in the system. Add Landlord env variables (format is the same as native DB connection):

```
LANDLORD_CONNECTION=
LANDLORD_HOST=
LANDLORD_PORT=
LANDLORD_DATABASE=
LANDLORD_USERNAME=
LANDLORD_PASSWORD=

```

Use native DB connection to provide connection for tenants but comment out `DB_DATABASE` as this will be dynamically switched during runtime.

```
DB_CONNECTION=
DB_HOST=
DB_PORT=
# DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

```

This means that all the tenants will be on a single connection but on separate databases. If you want to provide custom connection for some (or all) tenants, you can do so by providing that config within a DB table. More on that [later](#separate-tenant-connections).

Tenant aware commands
---------------------

[](#tenant-aware-commands)

Some native Artisan commands are modified to provide two additional options:

- `--tenant` - where you can provide a tenant ID for command to run on (i.e. `--tenant=1`). If you omit this argument, the command will run for **all** tenants.
- `--landlord` - will assume to run on landlord connection.

Commands currently available are:

- `migrate`
- `db:seed`
- `db:wipe`

Migrations
----------

[](#migrations)

Publish the migration by running:

`php artisan vendor:publish --tag="asseco-multitenancy-migrations"`

This will create a single migration within a `migrations/landlord` directory. Landlord represents a shared set of migrations which should be accessible independently of a chosen Tenant.

The default migration (`tenants` table) should hold all data related to tenants in the system. You are free to add other migrations there which would represent a shared set of tables across all tenants.

Migrate landlord files by running `php artisan migrate --landlord`

Once you have a `tenants` table, you can add a new tenant by manually filling out the DB or using Tinker (TODO: API + auto create). At that point, be sure to also create the database you specified in the table.

Example:

```
-------------------------------------
ID  Name    Domain          Database
-------------------------------------
1   Foo     foo.localhost   foo

```

Be sure that `foo` database exists on the server you defined within `.env`. At the point you hit `foo.localhost`, you will see the tenant switch to that particular DB.

Separate tenant connections
---------------------------

[](#separate-tenant-connections)

To provide a tenant with a completely custom DB connection edit its configuration in DB by filling out all the `db_` values in the `tenants` table. If one of the values is missing from the configuration, default will be used. Rest of the values will in that case be ignored.

Extending the package
---------------------

[](#extending-the-package)

Publish the configuration file by running:

`php artisan vendor:publish --tag="asseco-multitenancy-config"`

Extensible parts:

- `tenant_resolver` is the class responsible for figuring out who the current tenant is. Default resolution is by a domain. You can create a new class implementing `TenantResolver` interface and use it instead of the default one.
- `tenant_model` can be overridden, just be sure to extend the default `Tenant` model from the package.
- `switch_tenant_tasks` is an array of classes implementing `SwitchTenantTask` interface which are being ran when tenant is switched.

Final notes
===========

[](#final-notes)

Due to our specific use cases, this package was created as a merge of these 2 amazing multi tenancy packages:

- [Spatie multi-tenancy](https://spatie.be/docs/laravel-multitenancy/v2/introduction)
- [Archtechx tenancy](https://tenancyforlaravel.com/)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1468d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d61de45741b74e7d4a9ee5778160cf54ae5e94a615ae1a6f72b6d1e5fae68d12?d=identicon)[Norgul](/maintainers/Norgul)

---

Top Contributors

[![Norgul](https://avatars.githubusercontent.com/u/11718157?v=4)](https://github.com/Norgul "Norgul (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")

---

Tags

phplaraveldatabasemultitenancymicroservices

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asseco-voice-laravel-multitenancy/health.svg)

```
[![Health](https://phpackages.com/badges/asseco-voice-laravel-multitenancy/health.svg)](https://phpackages.com/packages/asseco-voice-laravel-multitenancy)
```

###  Alternatives

[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[codewithkyrian/chromadb-laravel

ChromaDB Laravel is a Laravel client for the Chroma Open Source Embedding Database

144.1k](/packages/codewithkyrian-chromadb-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
