PHPackages                             solutosoft/yii-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. [Database &amp; ORM](/categories/database)
4. /
5. solutosoft/yii-multitenant

ActiveYii-extension[Database &amp; ORM](/categories/database)

solutosoft/yii-multitenant
==========================

The shared database used by all tenants

1.1.0(6y ago)102.0k2BSD-3-ClausePHPCI failing

Since Oct 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/solutosoft/yii-multitenant)[ Packagist](https://packagist.org/packages/solutosoft/yii-multitenant)[ Docs](https://gitlab.com/solutosoft/yii2-base)[ RSS](/packages/solutosoft-yii-multitenant/feed)WikiDiscussions master Synced 1mo ago

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

Active Record MultiTenant Extension
===================================

[](#active-record-multitenant-extension)

This extension provides support for ActiveRecord MultiTenant.

[![Build Status](https://camo.githubusercontent.com/680a69d98dcf21ca0f1d1862d367a060302d143e66899afcfce5448a20cd0786/68747470733a2f2f7472617669732d63692e6f72672f736f6c75746f736f66742f7969692d6d756c746974656e616e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/solutosoft/yii-multitenant)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/db5a23b195403f54aa5bfc17963b3426b17ae934d6afe49473734b90086d66b1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6c75746f736f66742f7969692d6d756c746974656e616e742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/solutosoft/yii-multitenant/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/029ad4212301ac1e6f981b005f1ab7e567c6a27a8b1314bac93c2750a5aa7f57/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6c75746f736f66742f7969692d6d756c746974656e616e742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/solutosoft/yii-multitenant/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/4cafb7ba7eccda30e77e472fad0dc2e69bc5d99bbeec6f0535ea46bbc43665f1/68747470733a2f2f706f7365722e707567782e6f72672f736f6c75746f736f66742f7969692d6d756c746974656e616e742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/solutosoft/yii-multitenant)[![Latest Stable Version](https://camo.githubusercontent.com/d88bb5a6007c52593f84ff375039d4d12c2212b0f3371b1e1ae9c9b0fd347623/68747470733a2f2f706f7365722e707567782e6f72672f736f6c75746f736f66742f7969692d6d756c746974656e616e742f762f737461626c652e706e67)](https://packagist.org/packages/solutosoft/yii-multitenant)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist solutosoft/yii-multitenant

```

or add

```
"solutosoft/yii-multitenant": "*"
```

Usage
-----

[](#usage)

1. Creates table with `tenant_id` column:

```
class m191023_101232_create_post extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function up()
    {
        $this->createTable('post', [
            'id' =>  $this->primaryKey(),
            'title' => $this->string()->notNull(),
            'category_id' => $this->integer(),
            'content' => $this->string()
            'tenant_id' => $this->integer(),
        ]);

        $this->createTable('category', [
            'id' =>  $this->primaryKey(),
            'name' => $this->string()->notNull(),
            'tenant_id' => $this->integer(),
        ]);
    }
}
```

2. Adds `TenantInterface` to user model:

```
use solutosoft\multitenant\MultiTenantRecord;

class User extends MultiTenantRecord implements IdentityInterface, TenantInterface
{
    /**
     * {@inheritdoc}
     */
    public function getTenantId()
    {
        return // logic to determine tenant from current user
    }

    /**
     * Finds user by username attribute
     * This is an example where tenant filter is disabled
     */
    public static function findByUsername($username)
    {
        return static::find()->withoutTenant()->where(['username' => $username]);
    }

    ...

}
```

3. Extends models with `tenant_id` attribute from `MultiTenantRecord` intead of `ActiveRecord`:

```
use solutosoft\multitenant\MultiTenantRecord;

class Post extends MultiTenantRecord
{
    ...
}

class Category extends MultiTenantRecord
{
    ...
}
```

Now when you save or execute some query the `tenant_id` column will be used. Example:

```
// It's necessary the user will be logged in

$posts = \app\models\Post::find()->where(['category_id' => 1])->all();
// SELECT * FROM `post` WHERE `category_id` = 1 and `tenant_id` = 1;

$category = \app\models\Category([
  'name' => 'framework'
]);
$category->save();
// INSERT INTO `category` (`name`, `tenant_id`) values ('framework', 1);
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

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 ~123 days

Total

2

Last Release

2273d ago

### Community

Maintainers

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

---

Top Contributors

[![leandrogehlen](https://avatars.githubusercontent.com/u/1750751?v=4)](https://github.com/leandrogehlen "leandrogehlen (30 commits)")

---

Tags

activerecordmultitenancymultitenantyii2yii2-extensionyii2extensiontenantmultitenant

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/solutosoft-yii-multitenant/health.svg)

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

###  Alternatives

[dmstr/yii2-db

Database extensions

19618.8k6](/packages/dmstr-yii2-db)[sjaakp/yii2-spatial

Yii2 ActiveRecord supporting MySQL spatial data

1873.8k1](/packages/sjaakp-yii2-spatial)

PHPackages © 2026

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