PHPackages                             thisisdevelopment/laravel-tenants - 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. thisisdevelopment/laravel-tenants

ActiveLibrary

thisisdevelopment/laravel-tenants
=================================

A package to provide multi tenancy to laravel applications with minimal effort

0.1.3(5y ago)4553MITPHP

Since May 28Pushed 5y ago6 watchersCompare

[ Source](https://github.com/thisisdevelopment/laravel-tenants)[ Packagist](https://packagist.org/packages/thisisdevelopment/laravel-tenants)[ RSS](/packages/thisisdevelopment-laravel-tenants/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (5)Versions (5)Used By (0)

Laravel tenants
===============

[](#laravel-tenants)

A package to provide easy multi tenancy in your laravel application

After a simple setup (see below) you will have a fully functional multi tenancy app which out of the box:

- allows for many-to-many relationship between your users and tenant objects.
- supports easy switching between multiple tenants for a user which has access to multiple tenants (via `x-selected-tenant` header or via `selected-tenant` cookie)
- once switched by default only allows access to a single tenant object and you can easily implement tenant scoped models (see setup #4)
- allows to use tinker (or any other cli command) with a specific tenant (--tenant=)
- all jobs submitted from a context where a tenant is selected will use that tenant when executing from a queue
- when a tenant model is created the tenant database is automatically created

For an example see

Todo
====

[](#todo)

- integrate with laravel-test-snapshot
- proper seed support
- support sqlite
- cleanup
- ..

Setup
=====

[](#setup)

To setup multi tenancy with this package you'll need the following steps

### 1) include this package

[](#1-include-this-package)

```
composer require thisisdevelopment/laravel-tenants
```

### 2) find the model which serves as tenant (eg: customer/user) and implement our `Tenant` contract

[](#2-find-the-model-which-serves-as-tenant-eg-customeruser-and-implement-our-tenant-contract)

```
use Illuminate\Database\Eloquent\Model;
use ThisIsDevelopment\LaravelTenants\Contracts\Tenant;
use ThisIsDevelopment\LaravelTenants\Traits\ProvidesTenant;

class Customer extends Model implements Tenant
{
    use ProvidesTenant;

}
```

and register it in your `AppServiceProvider` class

```
use Illuminate\Support\ServiceProvider;
use ThisIsDevelopment\LaravelTenants\TenantsProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        TenantsProvider::setup(Customer::class);
    }
}
```

### 3) find the models which should live in tenant specific databases and use our `onTenantDB` trait

[](#3-find-the-models-which-should-live-in-tenant-specific-databases-and-use-our-ontenantdb-trait)

```
use Illuminate\Database\Eloquent\Model;
use ThisIsDevelopment\LaravelTenants\Traits\OnTenantDB;

class Test extends Model
{
    use OnTenantDB;
}
```

and move all of the migrations / seeders for these models to the `database/migrations/` / `database/seeds/` so they will only be used for tenant databases.

### 4) find the models which should be restricted once you switched to the tenant db and use our `TenantScoped` trait

[](#4-find-the-models-which-should-be-restricted-once-you-switched-to-the-tenant-db-and-use-our-tenantscoped-trait)

```
use Illuminate\Database\Eloquent\Model;
use ThisIsDevelopment\LaravelTenants\Traits\TenantScoped;
use Illuminate\Database\Eloquent\Builder;

class Settings extends Model
{
    use TenantScoped;

    public function scopeTenant(Builder $query, Customer $tenant): void
    {
       // custom filtering to limit this to what the current tenant is allowed to see
    }
}
```

### 5) (optional) find the model which you authenticate with and let it be responsible for providing the allowedTenants + defaultTenant by implementing the `TenantAuth` interface by using the `ProvidesTenantAuth` trait

[](#5-optional-find-the-model-which-you-authenticate-with-and-let-it-be-responsible-for-providing-the-allowedtenants--defaulttenant-by-implementing-the-tenantauth-interface-by-using-the-providestenantauth-trait)

```
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Collection;
use ThisIsDevelopment\LaravelTenants\Contracts\TenantAuth;
use ThisIsDevelopment\LaravelTenants\Traits\ProvidesTenantAuth;

class User extends Authenticatable implements TenantAuth
{
    use ProvidesTenantAuth;

    public function getAllowedTenants(): ?Collection
    {
        return $this->customers()->get();
    }

    public function getDefaultTenant()
    {
        return $this->getAllowedTenants()->first()->id;
    }

    public function customers(): BelongsToMany
    {
        return $this->belongsToMany(Customer::class, 'customer_users', 'user_id', 'customer_id');
    }

    public function scopeTenant(Builder $query, Customer $tenant): void
    {
        $query->whereIn($this->getKeyName(), $tenant->users()->get()->pluck('id')->all());
    }
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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

Every ~60 days

Total

4

Last Release

1991d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2e28c291bdd615f0334f50aef8fd3a08aa05283dfbc7e006b3b2bc6160804517?d=identicon)[ederuiter](/maintainers/ederuiter)

---

Top Contributors

[![ederuiter](https://avatars.githubusercontent.com/u/6728434?v=4)](https://github.com/ederuiter "ederuiter (8 commits)")[![sarptid](https://avatars.githubusercontent.com/u/58169857?v=4)](https://github.com/sarptid "sarptid (1 commits)")

---

Tags

laravelmulti-tenancytenants

### Embed Badge

![Health badge](/badges/thisisdevelopment-laravel-tenants/health.svg)

```
[![Health](https://phpackages.com/badges/thisisdevelopment-laravel-tenants/health.svg)](https://phpackages.com/packages/thisisdevelopment-laravel-tenants)
```

###  Alternatives

[stancl/tenancy

Automatic multi-tenancy for your Laravel application.

4.3k6.6M40](/packages/stancl-tenancy)[hyn/multi-tenant

Run multiple websites using the same laravel installation while keeping tenant specific data separated for fully independant multi-domain setups.

2.6k1.1M9](/packages/hyn-multi-tenant)[relaticle/custom-fields

User Defined Custom Fields for Laravel Filament

15828.6k](/packages/relaticle-custom-fields)[tomatophp/filament-tenancy

Tenancy multi-database integration for FilamentPHP

603.8k](/packages/tomatophp-filament-tenancy)[somnambulist/laravel-doctrine-tenancy

A multi-tenancy implementation that uses Laravel and Doctrine.

162.8k](/packages/somnambulist-laravel-doctrine-tenancy)[miracuthbert/laravel-multi-tenancy

A single database and multi-database multi-tenancy package for Laravel 5.8 and up

161.6k](/packages/miracuthbert-laravel-multi-tenancy)

PHPackages © 2026

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