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

ActiveLibrary[Database &amp; ORM](/categories/database)

iamkevinmckee/single-database-tenancy
=====================================

A simple package to create multi-tenant applications with a single database.

0.1(6y ago)07MITPHPPHP ^7.4CI failing

Since May 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/iAmKevinMcKee/single-database-tenancy)[ Packagist](https://packagist.org/packages/iamkevinmckee/single-database-tenancy)[ Docs](https://github.com/iamkevinmckee/single-database-tenancy)[ RSS](/packages/iamkevinmckee-single-database-tenancy/feed)WikiDiscussions master Synced today

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

Single Database Multi Tenancy for Laravel
=========================================

[](#single-database-multi-tenancy-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0ecc9d720e6674b9b3fce4e1d8c2803532faacdac3f355624c18b1d150dd4c45/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69616d6b6576696e6d636b65652f73696e676c652d64617461626173652d74656e616e63792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iamkevinmckee/single-database-tenancy)[![Total Downloads](https://camo.githubusercontent.com/9a4dfd523683c86f5618bf288bfc65958d2a081b628fe1174e7818fee0ca6fac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69616d6b6576696e6d636b65652f73696e676c652d64617461626173652d74656e616e63792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iamkevinmckee/single-database-tenancy)

This is a package to help you create a multi-tenant application in Laravel with a single database. It is best used at the beginning of a new project.

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

[](#installation)

You can install the package via composer:

```
composer require iamkevinmckee/single-database-tenancy
```

Usage
-----

[](#usage)

After installing the package, you will need to create a Tenant model.

```
php artisan make:model Tenant -m
```

You will also need to add a `tenant_id` to your `users` table.

```
php artisan make:migration add_tenant_id_to_users_table
```

Next you will want to publish the stubs. This will ensure every subsequent model has a migration with a `tenant_id`. For this to work, you must create your models with the `-m` flag so a migration is also created with the model.

```
php artisan single-db-tenancy:stubs
```

At this point, you just need to make sure each User has a tenant\_id assigned to them when they register and all Eloquent operations will be scoped to the tenant.

When inserting data into the database via Eloquent, the `tenant_id` will automatically be set to the `tenant_id` of the user submitting the data.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please open an issue before submitting a PR to ensure the feature will be accepted.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Kevin McKee](https://github.com/iamkevinmckee)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

2226d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4503765?v=4)[Kevin McKee](/maintainers/iamkevinmckee)[@iAmKevinMcKee](https://github.com/iAmKevinMcKee)

---

Top Contributors

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

---

Tags

laravelmulti-tenantmulti-tenancysingle-database-tenancylaravel multi-tenant

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/iamkevinmckee-single-database-tenancy/health.svg)

```
[![Health](https://phpackages.com/badges/iamkevinmckee-single-database-tenancy/health.svg)](https://phpackages.com/packages/iamkevinmckee-single-database-tenancy)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M94](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M1](/packages/glushkovds-phpclickhouse-laravel)[lemaur/eloquent-publishing

218.1k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

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