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

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

sbine/simple-tenancy
====================

Simple Laravel multi-tenancy in the same database

0.0.7(10mo ago)373.4k5MITPHPPHP ^8.2CI passing

Since Jan 12Pushed 10mo ago2 watchersCompare

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

READMEChangelogDependencies (2)Versions (8)Used By (0)

Simple Laravel Multi-Tenancy
============================

[](#simple-laravel-multi-tenancy)

[![Build status](https://camo.githubusercontent.com/9c54fa30cd7ad5f166abd9b978b9d993de988bb7ba73835262a66d11dce7611a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7362696e652f73696d706c652d74656e616e63792f74657374732e796d6c3f6272616e63683d6d61696e)](https://camo.githubusercontent.com/9c54fa30cd7ad5f166abd9b978b9d993de988bb7ba73835262a66d11dce7611a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7362696e652f73696d706c652d74656e616e63792f74657374732e796d6c3f6272616e63683d6d61696e)

Simple Tenancy adds automatic multi-tenant support to Eloquent models stored in a shared database.

It requires zero configuration in most cases, relying on established Laravel conventions and a single column on each table.

### How it works

[](#how-it-works)

Under the hood, it has only 4 components:

1. `Tenant`: Keeps track of the current user
2. `HasTenancy`: A trait for models belonging to the tenant, which registers:
3. `TenancyScope`: A [global scope](https://laravel.com/docs/master/eloquent#global-scopes) limiting all the model's queries to the current tenant
4. `TenancyObserver`: An [observer](https://laravel.com/docs/master/eloquent#observers) which sets the current tenant column/identifier on save

By default, the tenant is Laravel's `Auth::user()`, and all tenancy checks are disabled when no one is authenticated.

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

[](#installation)

1. Install using Composer:

```
composer require sbine/simple-tenancy
```

2. Add the `HasTenancy` trait to all models belonging to the tenant:

```
class Account extends Model
{
    use \Sbine\Tenancy\HasTenancy;
}
```

3. Ensure a `user_id` column exists on the table of every model using the trait.

Customizing the tenant column/ID
--------------------------------

[](#customizing-the-tenant-columnid)

If needed, you can customize the name of the tenant column or identifier by extending the Tenant class and [binding it into the container](#customizing-tenancy-behavior):

```
class MyTenant extends \Sbine\Tenancy\Tenant
{
    /**
     * Retrieve the column identifying each model's tenant.
     */
    public function column()
    {
        return 'tenant_hashid';
    }

    /**
     * Retrieve the current tenant's identifier.
     */
    public function id()
    {
        return $this->user->hashid;
    }
}
```

Customizing tenancy behavior
----------------------------

[](#customizing-tenancy-behavior)

By default, if no user is authenticated tenancy will be completely disabled. This is by design so the library doesn't interfere with testing, seeding, and other unauthenticated model usage.

To change the tenancy behavior in any way, you can override the Tenant binding in the application container.

For example, to prevent all querying and saving of tenant models when no one is authenticated:

```
    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            // Throw an AuthenticationException if auth check fails
            return new \Sbine\Tenancy\Tenant(Auth::authenticate());
        });
    }
```

To allow overriding tenancy checks based on a policy or method, pass a callback returning `true` or `false`:

```
    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            return new \Sbine\Tenancy\Tenant(Auth::user(), function ($user) {
                return $user->can('admin');
            });
        });
    }
```

For complete control over tenant behavior, you can bind your own Tenant implementation:

```
    // In AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Sbine\Tenancy\Tenant::class, function () {
            return new MyTenant;
        });
    }
```

Disabling tenancy
-----------------

[](#disabling-tenancy)

For convenience, a SuperAdmin class is provided which you can bind at any time to disable tenant checks:

```
    $this->app->singleton(\Sbine\Tenancy\Tenant::class, \Sbine\Tenancy\SuperAdmin::class);
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance53

Moderate activity, may be stable

Popularity33

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 87.1% 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 ~330 days

Recently: every ~425 days

Total

7

Last Release

326d ago

PHP version history (5 changes)0.0.1PHP ^7.2

0.0.3PHP ^7.3

0.0.5PHP ^7.3 || ^8.0

0.0.6PHP ^7.4 || ^8.0

0.0.7PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![sbine](https://avatars.githubusercontent.com/u/1902973?v=4)](https://github.com/sbine "sbine (27 commits)")[![ryanwohara](https://avatars.githubusercontent.com/u/5102611?v=4)](https://github.com/ryanwohara "ryanwohara (4 commits)")

---

Tags

hacktoberfestlaravelmulti-tenancylaravelSimplemultitenancy

### Embed Badge

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

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

###  Alternatives

[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)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[tenancy/tenancy

Creating multi tenant saas from your Laravel app with ease

1.3k43.6k](/packages/tenancy-tenancy)[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)
