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. iamkevinmckee/single-database-tenancy

ActiveLibrary

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

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

0.1(5y ago)07MITPHPPHP ^7.4

Since May 29Pushed 5y 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 1mo ago

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 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

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

2171d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2465b1648310aaeaabcb11b1ffc4a5f9bf8389b3751876b0752d7d4e33f1251?d=identicon)[iamkevinmckee](/maintainers/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

[stancl/tenancy

Automatic multi-tenancy for your Laravel application.

4.3k6.6M40](/packages/stancl-tenancy)[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)[andrewdwallo/filament-companies

A comprehensive Laravel authentication and authorization system designed for Filament, focusing on multi-tenant company management.

34450.0k2](/packages/andrewdwallo-filament-companies)

PHPackages © 2026

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