PHPackages                             fantismic/tenancy - 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. [Framework](/categories/framework)
4. /
5. fantismic/tenancy

ActiveLibrary[Framework](/categories/framework)

fantismic/tenancy
=================

A package to manage multi-tenancy in Laravel applications.

1.0.19(9mo ago)0117MITPHP

Since Jul 14Pushed 9mo agoCompare

[ Source](https://github.com/fantismic/tenancy)[ Packagist](https://packagist.org/packages/fantismic/tenancy)[ RSS](/packages/fantismic-tenancy/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (14)Used By (0)

**Fantismic/Tenancy**

A Laravel package to build multi-tenant applications with separate databases per tenant on a single domain.

Features
--------

[](#features)

- **Tenant Provisioning**: Create tenant-specific databases and database users automatically.
- **Multi-Database Support**: Each tenant gets its own MySQL database connection.
- **Migrations &amp; Seeders**: Run migrations and seeders per tenant.
- **Tenant Isolation**: Use the `UsesTenantConnection` trait to isolate Eloquent models to the tenant database.
- **Middleware**: Automatically initialize tenant context based on authenticated user.
- **Artisan Commands**: Manage tenant migrations via console command.
- **Admin Panel**: Out-of-the-box routes, controllers, and views for tenant administration (list, migrate, sync users, delete).

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 10.0
- MySQL

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

[](#installation)

```
composer require fantismic/tenancy
```

Service Provider &amp; Facades
------------------------------

[](#service-provider--facades)

This package uses auto-discovery. The following service providers and facades are registered:

- **Service Providers**:

    - `Fantismic\Tenancy\TenancyServiceProvider`
- **Facades**:

    - `Tenancy` (alias for `Fantismic\Tenancy\Helpers\TenantManager`)
    - `TenantAdmin` (alias for `Fantismic\Tenancy\Services\TenantAdminService`)

Database Migrations
-------------------

[](#database-migrations)

Publish and run the central migrations:

```
php artisan vendor:publish --provider="Fantismic\Tenancy\TenancyServiceProvider" --tag="migrations"
php artisan migrate
```

This will create:

- `tenants` table
- `tenant_user` pivot table
- Tenant-specific migration stub directory at `database/migrations/tenant`

Configuration
-------------

[](#configuration)

No configuration file is published. Tenant connection settings are stored in the `connection` JSON column of the `tenants` table. You can customize connection parameters when creating a tenant.

Usage
-----

[](#usage)

### Creating a Tenant

[](#creating-a-tenant)

Use the `Tenancy` facade to create a new tenant:

```
use Fantismic\Tenancy\Facades\Tenancy;

$tenant = Tenancy::createTenant(
    'Tenant Name',            // Tenant display name
    [                         // Connection details for admin user
        'driver'         => 'mysql',
        'host'           => '127.0.0.1',
        'database'       => 'admin_db',
        'username'       => 'root',
        'password'       => 'secret',
    ],
    [                         // Options
        'create_db' => true,  // Create database & user (default: true)
        'migrate'   => true,  // Run tenant migrations (default: true)
        'seed'      => null,  // Seeder class to run (optional)
    ]
);
```

This will:

1. Generate a UUID for the tenant.
2. Create a database named `tenant_{uuid}` and a user `u_{uuid}` with random password.
3. Store the connection JSON in the `tenants` table.
4. Run tenant migrations in `database/migrations/tenant`.
5. Return the `Tenant` model instance.

### Artisan Command

[](#artisan-command)

Run migrations for an existing tenant:

```
php artisan tenants:migrate {tenant_id}
```

### Eloquent Models

[](#eloquent-models)

Use the `UsesTenantConnection` trait on any model that should use the tenant database:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Fantismic\Tenancy\Traits\UsesTenantConnection;

class Invoice extends Model
{
    use UsesTenantConnection;
    // ...
}
```

### Middleware

[](#middleware)

Protect tenant routes and initialize tenant context:

```
use Fantismic\Tenancy\Http\Middleware\InitializeTenant;

Route::middleware([
    'auth',
    InitializeTenant::class,
])->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
});
```

### Admin Panel

[](#admin-panel)

The package provides a simple administrative UI. Publish views:

```
php artisan vendor:publish --provider="Fantismic\Tenancy\TenancyServiceProvider" --tag="views"
```

Then visit `/admin/tenants` to manage tenants.

Supported actions:

- List tenants
- Migrate tenant database
- Sync users from central to tenant pivot
- Delete tenant and drop its database

Facades &amp; Services
----------------------

[](#facades--services)

- **`Tenancy`** (`TenantManager`): Tenant creation, migrations, and seeding.
- **`TenantAdmin`** (`TenantAdminService`): Fetch, migrate, sync users, and delete tenants.

Events &amp; Listeners
----------------------

[](#events--listeners)

The package listens to the `Login` event to set the current tenant in session:

- `Fantismic\Tenancy\Listeners\SetTenantSession`

Contributing
------------

[](#contributing)

Feel free to submit issues or pull requests. Follow PSR-12 coding standards and include tests for new features.

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance56

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

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

13

Last Release

294d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/984d8f1b0964c85832a90864e5e3e6526d0299d4d06093dae94513a2c9d48196?d=identicon)[fantismic](/maintainers/fantismic)

### Embed Badge

![Health badge](/badges/fantismic-tenancy/health.svg)

```
[![Health](https://phpackages.com/badges/fantismic-tenancy/health.svg)](https://phpackages.com/packages/fantismic-tenancy)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M190](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M256](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M591](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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