PHPackages                             revoltify/tenantify - 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. revoltify/tenantify

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

revoltify/tenantify
===================

Single database multi-tenant solution for Laravel

1.1.0(11mo ago)72.0k↓35.7%MITPHPPHP ^8.2CI passing

Since Jan 31Pushed 11mo agoCompare

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

READMEChangelog (4)Dependencies (6)Versions (5)Used By (0)

Tenantify
=========

[](#tenantify)

[![Latest Version on Packagist](https://camo.githubusercontent.com/be4de95e141b54806ee901209086bb6359890fb4f3556a060f6bca1d16bf2b98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7265766f6c746966792f74656e616e746966792e737667)](https://packagist.org/packages/revoltify/tenantify)[![Total Downloads](https://camo.githubusercontent.com/9e484587cc79b3343f021c077d0b53a9661a933412c8b229d6d0e37b26639722/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7265766f6c746966792f74656e616e746966792e737667)](https://packagist.org/packages/revoltify/tenantify)[![Tests](https://github.com/revoltify/tenantify/actions/workflows/run-tests.yml/badge.svg)](https://github.com/revoltify/tenantify/actions/workflows/run-tests.yml)[![License](https://camo.githubusercontent.com/c5fd3f1f5e54746964bf9a1f4e207b9d7375cdc4648c77ed965d9f58fdd517a2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7265766f6c746966792f74656e616e74696679)](https://github.com/revoltify/tenantify/blob/main/LICENSE.md)

A powerful and flexible single-database multi-tenant solution for Laravel 11+, built with SOLID principles in mind.

Features
--------

[](#features)

- **Early Identification**: Initialize tenants during application boot for maximum performance
- **Flexible Resolution**: Support for domain and subdomain-based tenant resolution
- **Customizable Bootstrapping**: Add your own tenant bootstrapping logic
- **Tenant-Aware Systems**:
    - Queue system with automatic tenant context
    - Cache system with tenant-specific prefixes
    - Session management with tenant isolation
- **Built-in Spatie Permissions Support**: Automatic tenant-specific permission caching
- **Automatic Tenant Scoping**: Zero-effort tenant data isolation with the `BelongsToTenant` trait
- **High Performance**: Optimized resolver with optional caching
- **Developer Friendly**: Clear API with helper functions

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

[](#requirements)

- PHP 8.2 or higher
- Laravel 11.x or higher

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

[](#installation)

1. Install the package via Composer:

```
composer require revoltify/tenantify
```

2. Run the installation command:

```
php artisan tenantify:install
```

This will publish the configuration file and migrations.

3. Run the migrations:

```
php artisan migrate
```

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

[](#configuration)

The package can be configured via the `config/tenantify.php` file. Here are the key configuration options:

### Early Initialization

[](#early-initialization)

```
'early' => env('TENANTIFY_EARLY', false),
```

- `true`: Initializes tenant during application boot (recommended for fully tenant-aware applications)
- `false`: Manual initialization through middleware (recommended for partially tenant-aware applications)

### Custom Models

[](#custom-models)

```
'models' => [
    'tenant' => \App\Models\Tenant::class,
    'domain' => \App\Models\Domain::class,
],
```

### Resolver Configuration

[](#resolver-configuration)

```
'resolver' => [
    'class' => \Revoltify\Tenantify\Resolvers\DomainResolver::class,
    'cache' => [
        'enabled' => env('TENANTIFY_CACHE_ENABLED', false),
        'ttl' => env('TENANTIFY_CACHE_TTL', 3600),
    ],
],
```

Basic Usage
-----------

[](#basic-usage)

### Creating a Tenant

[](#creating-a-tenant)

```
use Revoltify\Tenantify\Models\Tenant;
use Revoltify\Tenantify\Models\Domain;

$tenant = Tenant::create([
    'name' => 'Example Organization'
]);

$tenant->domains()->create([
    'domain' => 'example.com'
]);
```

### Manual Tenant Initialization

[](#manual-tenant-initialization)

```
// Using facade
Tenantify::initialize($tenant);

// Using helper function
tenantify()->initialize($tenant);

// Initialize by ID
tenantify()->initialize($tenantId);
```

### Accessing Current Tenant

[](#accessing-current-tenant)

```
// Using helper functions
$tenant = tenant();
$tenantId = tenant_id();

// Using facade
$tenant = Tenantify::tenant();
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Bootstrapper

[](#custom-bootstrapper)

Create a custom bootstrapper by extending the `AbstractBootstrapper` class:

```
use Revoltify\Tenantify\Bootstrappers\AbstractBootstrapper;
use Revoltify\Tenantify\Models\Contracts\TenantInterface;

class CustomBootstrapper extends AbstractBootstrapper
{
    protected int $priority = 10;

    public function bootstrap(TenantInterface $tenant): void
    {
        // Your bootstrapping logic here
    }

    public function revert(): void
    {
        // Your cleanup logic here
    }
}
```

Register your bootstrapper in the configuration:

```
'bootstrappers' => [
    \App\Bootstrappers\CustomBootstrapper::class,
],
```

### Model Tenant Scoping

[](#model-tenant-scoping)

Add automatic tenant scoping to your models using the `BelongsToTenant` trait:

```
use Illuminate\Database\Eloquent\Model;
use Revoltify\Tenantify\Models\Concerns\BelongsToTenant;

class Project extends Model
{
    use BelongsToTenant;

    protected $fillable = ['name', 'description'];
}
```

This will automatically:

- Add tenant ID on model creation
- Scope all queries to the current tenant
- Establish the tenant relationship

Usage example:

```
// Creates a project for the current tenant automatically
$project = Project::create([
    'name' => 'New Project'
]);

// Queries are automatically scoped to the current tenant
$projects = Project::all(); // Only returns current tenant's projects

// Access the tenant relationship
$tenant = $project->tenant;
```

### Tenant-Aware Jobs

[](#tenant-aware-jobs)

Make your job tenant-aware by implementing the `TenantAware` interface:

```
use Illuminate\Contracts\Queue\ShouldQueue;
use Revoltify\Tenantify\Job\TenantAware;

class ProcessTenantData implements ShouldQueue, TenantAware
{
    public function handle(): void
    {
        // Job will automatically run in the correct tenant context
    }
}
```

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

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Revoltify](https://github.com/revoltify)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance50

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.8% 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 ~39 days

Total

4

Last Release

355d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a6975c50488b3eeb7cb613bf0b280342ce3912dc4ffaa1aa14b75add8fe070a?d=identicon)[rtraselbd](/maintainers/rtraselbd)

---

Top Contributors

[![rtraselbd](https://avatars.githubusercontent.com/u/31556372?v=4)](https://github.com/rtraselbd "rtraselbd (45 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/revoltify-tenantify/health.svg)

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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