PHPackages                             dersam/laravel-multitenant - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dersam/laravel-multitenant

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dersam/laravel-multitenant
==========================

Multitenant service provider for laravel

v0.1.2(8y ago)09MITPHPPHP &gt;=7.0.0

Since Nov 18Pushed 8y agoCompare

[ Source](https://github.com/dersam/laravel-multitenant)[ Packagist](https://packagist.org/packages/dersam/laravel-multitenant)[ RSS](/packages/dersam-laravel-multitenant/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

multitenant
===========

[](#multitenant)

Simple multitenant service provider for Laravel. Individual tenants will be given their own database schema. It expects a separate "core" schema for managing application-wide settings.

This does not support multitenancy via owner columns, and never will.

Installation
------------

[](#installation)

Install the package: `composer require dersam/laravel-multitenant`

Run the migration to create the `tenants` database in your core database. `php artisan migrate`

Deploy the config. `php artisan vendor:publish --provider="Dersam\Multitenant\ServiceProvider"`

Add a "dummy" config to `config/database.php` It should point to the database you want to contain your tenant schemas, but do not specify a database. This will be set dynamically.

```
'connections' => [
    // The core database that contains global application tables.
    'core' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],
    // A "dummy" database that will be pointed to the correct tenant on the fly.
    'tenant' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
    ],
],

```

Usage
-----

[](#usage)

The service provider will be automatically registered - it can be injected with `Dersam\Multitenant\TenantSwitcher`. Retrieve your `Tenant` model, and pass that to switch the `tenant` connection to your new database. In this example, it is assumed that the User model has a `tenant_id` column, but this package leaves it up to the developer to decide where this comes from.

```
$tenant = Tenant::find($user->tenant_id);
if ($tenant === null) {
    return redirect('/');
}
$this->tenantSwitcher->switchGlobalTenant($tenant);

```

You can specify that certain models always use the tenant connection with the `Dersam\Multitenant\IsTenantModel` trait.

```
namespace App\Models\Tenant;

use Dersam\Multitenant\IsTenantModel;
...

class ExampleModel extends Model
{
    use IsTenantModel;
...

```

You can specify migrations that are run only on tenant databases by placing them in the `database/migrations/tenant` directory. Migrations can be run on all tenants with `php artisan multitenant:migrate` and rolled back with `php artisan multitenant:migrate:rollback`. These commands will read the `tenants` table and automatically discover the relevant tenant databases. Each tenant maintains its own migration table.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

3097d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/475851?v=4)[Sam Schmidt](/maintainers/dersam)[@dersam](https://github.com/dersam)

---

Top Contributors

[![dersam](https://avatars.githubusercontent.com/u/475851?v=4)](https://github.com/dersam "dersam (13 commits)")

---

Tags

laravelmultitenantlaravelmultitenant

### Embed Badge

![Health badge](/badges/dersam-laravel-multitenant/health.svg)

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

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)

PHPackages © 2026

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