PHPackages                             skillup/tenant-scope - 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. skillup/tenant-scope

ActiveLibrary[Framework](/categories/framework)

skillup/tenant-scope
====================

Strong Global Scope package for Laravel multi-tenant systems

1.0.0(9mo ago)12MITPHPPHP &gt;=8.1

Since Jul 31Pushed 9mo agoCompare

[ Source](https://github.com/talenta-eg/tenant-scope)[ Packagist](https://packagist.org/packages/skillup/tenant-scope)[ RSS](/packages/skillup-tenant-scope/feed)WikiDiscussions main Synced 1mo ago

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

Tenant Scope (Strong Global Scope for Laravel)
==============================================

[](#tenant-scope-strong-global-scope-for-laravel)

This package provides shared `tenant_id` global scoping across Laravel services.

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

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require skillup/tenant-scope
```

If you're using it locally, add the repo to your `composer.json`:

```
"repositories": [
    {
        "type": "path",
        "url": "../packages/tenant-scope"
    }
]
```

### 2. Publish Config (Optional)

[](#2-publish-config-optional)

```
php artisan vendor:publish --tag=config
```

### 3. Usage in Model

[](#3-usage-in-model)

```
use TenantScope\Traits\BelongsToTenant;

class User extends Model
{
    use BelongsToTenant;

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

### 4. Set Tenant Context on (Request, Jobs, Artisan)

[](#4-set-tenant-context-on-request-jobs-artisan)

Unit tests In your Background jobs , Artisan commands and Unit tests:

```
TenantContext::setTenantId($request->header('X-Tenant-ID'));
```

### 5. Set Tenant Context from Middleware

[](#5-set-tenant-context-from-middleware)

Once your package is installed:

- The middleware is auto-registered as `tenant.context`
- You can get `tenant_id` from `header` or `jwt`
- You can use it in routes:

```
Route::middleware('tenant.context')->group(function () {
   // Get only users belongs to the tenant
   $users= \App\Models\User::all()->toArray();

});
```

How to Use in Microservices
---------------------------

[](#how-to-use-in-microservices)

- Include the package via Composer
- Call `TenantContext::setTenantId($id)` early in the request lifecycle
- Add `use BelongsToTenant` on all tenant-scoped models

Indexing Best Practice
----------------------

[](#indexing-best-practice)

In Laravel migration:

```
$table->index(['tenant_id', 'email']); // Composite index with tenant_id first
```

---

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance56

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

291d ago

### Community

Maintainers

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

---

Top Contributors

[![talenta-eg](https://avatars.githubusercontent.com/u/4216438?v=4)](https://github.com/talenta-eg "talenta-eg (1 commits)")

### Embed Badge

![Health badge](/badges/skillup-tenant-scope/health.svg)

```
[![Health](https://phpackages.com/badges/skillup-tenant-scope/health.svg)](https://phpackages.com/packages/skillup-tenant-scope)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k96.9M674](/packages/laravel-socialite)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.1k84.2M225](/packages/laravel-horizon)[laravel/ui

Laravel UI utilities and presets.

2.7k134.9M601](/packages/laravel-ui)[laravel/jetstream

Tailwind scaffolding for the Laravel framework.

4.1k19.8M136](/packages/laravel-jetstream)[stancl/tenancy

Automatic multi-tenancy for your Laravel application.

4.3k6.6M40](/packages/stancl-tenancy)[internachi/modular

Modularize your Laravel apps

1.1k662.4k8](/packages/internachi-modular)

PHPackages © 2026

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