PHPackages                             aura-is-here/laravel-multi-tenant - 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. aura-is-here/laravel-multi-tenant

Abandoned → [hipsterjazzbo/landlord](/?search=hipsterjazzbo%2Flandlord)Library

aura-is-here/laravel-multi-tenant
=================================

v0.1.0(10y ago)14618.1k34[4 issues](https://github.com/hipsterjazzbo/laravel-multi-tenant/issues)PHPPHP &gt;=5.4.0CI failing

Since Oct 27Pushed 10y ago25 watchersCompare

[ Source](https://github.com/hipsterjazzbo/laravel-multi-tenant)[ Packagist](https://packagist.org/packages/aura-is-here/laravel-multi-tenant)[ RSS](/packages/aura-is-here-laravel-multi-tenant/feed)WikiDiscussions master Synced 1mo ago

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

Laravel Multi Tenant
====================

[](#laravel-multi-tenant)

---

---

---

NOTE: THIS PACKAGE HAS MOVED
----------------------------

[](#note-this-package-has-moved)

This package is now Laravel 5.2+ only, and has moved to .

This version will no longer be maintained, but will stay here for legacy compatibility.

---

---

---

[![](https://camo.githubusercontent.com/8441d30396480adca5ae980133a037003c5cb07c65d8a7e1701d9e4239fd4a73/68747470733a2f2f7472617669732d63692e6f72672f4175726145512f6c61726176656c2d6d756c74692d74656e616e742e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/8441d30396480adca5ae980133a037003c5cb07c65d8a7e1701d9e4239fd4a73/68747470733a2f2f7472617669732d63692e6f72672f4175726145512f6c61726176656c2d6d756c74692d74656e616e742e7376673f6272616e63683d6d6173746572)

A general purpose multi-tenancy package for Laravel 5.2+. Accidentally derived from the work of [@tonydew](https://github.com/tonydew), and with help from [@rizqidjamaluddin](https://github.com/rizqidjamaluddin)

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

[](#installation)

To get started, require this package in your composer.json and run composer update:

```
"aura-is-here/laravel-multi-tenant": "dev-master"
```

After updating composer, add the ServiceProvider to the providers array in `app/config/app.php`:

```
AuraIsHere\LaravelMultiTenant\LaravelMultiTenantServiceProvider::class,
```

You'll probably want to set up the alias:

```
'TenantScope' => AuraIsHere\LaravelMultiTenant\Facades\TenantScopeFacade::class
```

You could also publish the config file:

```
php artisan vendor:publish --provider="AuraIsHere\LaravelMultiTenant\LaravelMultiTenantServiceProvider"
```

and set up your `tenant_column` setting, if you have an app-wide default.

Usage
-----

[](#usage)

First off, this package assumes that you have a column on all of your tenant-scoped tables that references which tenant each row belongs to.

For example, you might have a `companies` table, and all your other tables might have a `company_id` column (with a foreign key, right?).

Next, you'll have to call `TenantScope::addTenant($tenantColumn, $tenantId)`. It doesn't matter where, **as long as it happens on every request**. This is important; if you only set the tenant in your login method for example, that won't run for subsequent requests and queries will no longer be scoped.

Some examples of good places to call `TenantScope::addTenant($tenantColumn, $tenantId)` might be:

- In a global Middleware
- In an oauth system, wherever you're checking the token on each request
- In the constructor of a base controller

Once you've got that all worked out, simply `use` the trait in all your models that you'd like to scope by tenant:

```
