PHPackages                             lukapeharda/multitenancy - 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. lukapeharda/multitenancy

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

lukapeharda/multitenancy
========================

A single DB multitenancy package for Laravel based on subdomain routing.

v1.0.2(9y ago)117MITPHPPHP &gt;=5.6.4

Since Jan 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/lukapeharda/multitenancy)[ Packagist](https://packagist.org/packages/lukapeharda/multitenancy)[ RSS](/packages/lukapeharda-multitenancy/feed)WikiDiscussions master Synced today

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

MultiTenancy
============

[](#multitenancy)

Introduction
------------

[](#introduction)

MultiTenancy is a Laravel single DB multitenancy package based on subdomain routing.

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

[](#installation)

Require this package, with [Composer](https://getcomposer.org/), in the root directory of your project.

```
composer require lukapeharda/multitenancy
```

Add the service provider to `config/app.php` in the `providers` array.

```
LukaPeharda\MultiTenancy\Providers\ContextServiceProvider::class,
```

Publish the config file and modify its params to fit your needs and installation.

```
php artisan vendor:publish --provider="LukaPeharda\MultiTenancy\Providers\ContextServiceProvider"
```

Usage
-----

[](#usage)

Add the `LukaPeharda\MultiTenancy\Scopes\Contextable` trait to your models that are "tenant" dependable. This trait will automatically load global scope which will filter all your queries by defined tenant key.

Beside adding trait to your models, your model DB schema needs to have the tenant key as its attribute (and most likely as its foreign key).

To disable tenant global scope use `withoutGlobalScope` builder method:

```
$model->withoutGlobalScope(\LukaPeharda\MultiTenancy\Scopes\TenantScope::class);
```

Fetching the current tenant (and all of its attributes) is available through helper function `context`.

```
// To fetch entire tenant object
$tenant = context();

// To fetch one of its attribute
$tenantId = context('id');
```

License
-------

[](#license)

MultiTenancy is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

3442d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelmultitenancytenantlaravelsaastenantmultitenancytenancymultitenant

### Embed Badge

![Health badge](/badges/lukapeharda-multitenancy/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.7k](/packages/larastan-larastan)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

15104.9k4](/packages/calebdw-larastan)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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