PHPackages                             gpopoteur/flat - 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. gpopoteur/flat

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

gpopoteur/flat
==============

Laravel 5 package for creating multi-tenant apps.

v0.0.1(10y ago)16202MITPHPPHP &gt;=5.4.0

Since Jul 26Pushed 9y ago4 watchersCompare

[ Source](https://github.com/gpopoteur/flat)[ Packagist](https://packagist.org/packages/gpopoteur/flat)[ Docs](https://github.com/gpopoteur/flat)[ RSS](/packages/gpopoteur-flat/feed)WikiDiscussions master Synced 1mo ago

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

Flat
====

[](#flat)

***WORK IN PROGRESS!!***

Laravel 5 package for creating multi-tenant apps. As of right now only Postgresql Schemas and SQLite Databases are supported.

Install
-------

[](#install)

Install via composer with the command:

```
composer require gpopoteur/flat

```

Then register the provider in the `config/app.php` file:

```
    'GPopoteur\Flat\FlatServiceProvider',
```

After that you can start using the `Flat` API! :)

The Database driver used by `flat` will be the same one specified in `config/database.php`, meaning the same that you are using for your application.

Usage
-----

[](#usage)

You can inject the dependency with Laravel IoC container:

```
    public function __contruct(Flat $flat){
        // business logic
    }
```

Or just let the `App::make()` resolve the class.

```
    $flat = App::make('GPopoteur\Flat\Flat');
```

### Creating a new Flat

[](#creating-a-new-flat)

To create a new Flat (Tenant), just call the `build($name)` method of the `Flat` class passing the new Tenant name.

```
    $flat->build('new-tenant');
```

After you create a new tenant, the new Schema is not automatically migrated, to run the migrations just run:

```
    $flat->migrate('new-tenant');
```

or, if migrating several tenants at once, pass an array with the tenants names:

```
    $flat->migrate(['new-tenant', 'other-tenant', 'and-another']);
```

Changing Flats (Tenants)
------------------------

[](#changing-flats-tenants)

To change the Tenant programatically you can call the `moveIn($name)` method of the `Flat` API.

```
    $flat->moveIn('new-tenant');
```

There is a middleware implemented called `FlatCheckInMiddleware`, basically what it does is to take the name of the variable `flatName` and change the user to that Schema.

To register this middleware you need to add the following line to the `$routeMiddleware` variable in the `app/Http/Kernel.php` file:

```
    'flatCheckIn' => 'GPopoteur\Flat\Middleware\FlatCheckInMiddleware'
```

and you should be ready to go.

Example:

### Subdomain tenant

[](#subdomain-tenant)

To be able to do a subdomain tenant, just add a `flatName` variable and the `flatCheckIn` middleware to your domain route group.

```
    Route::group(['domain' => '{flatName}.domain.com', 'middleware' => 'flatCheckIn'], function(){

        // everything inside this closure will be done in the `flatName` schema.

    });
```

### Route name tenant

[](#route-name-tenant)

Because the `flatName` variable is assigned in the route, you can add that variable to any route group that fits your need, example:

```
    Route::group(['prefix' => 'account/{flatName}', 'middleware' => 'flatCheckIn'], function(){

        // everything inside this closure will be done in the `flatName` schema.

    });
```

When using the provided Middlewares, if a tenant doesn't exists the middleware will throw a new `FlatDoesntExistsException` that you can catch globally in the app and then redirect the user somewhere and show then a nice error message.

### Contributing

[](#contributing)

Contributions to the library are more than welcome. To contribute code to this repo, follow this simple steps:

1. Fork this project.
2. Create a new branch. Ex: `feature/this-thing`
3. Commit &amp; Push the changes to your repo.
4. Do a Pull Request from your branch to the `develop` branch of this repo.

Thanks :)

### Disclaimer

[](#disclaimer)

Because this package works with the database, and the data is the more critical part of a production app I make the following statement:

> I am not responsible in any way for any harm that this library does to your data. This package comes as-is. Use at your own risk.

### License

[](#license)

MIT

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

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

3949d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/33cd4d374c94a758bb152cddbf95999f1ec7553105535fa12cc6134d87df38b0?d=identicon)[gpopoteur](/maintainers/gpopoteur)

---

Top Contributors

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

---

Tags

databasesaastenantmulti-tenant

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gpopoteur-flat/health.svg)

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

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M191](/packages/spatie-laravel-backup)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[kreait/laravel-firebase

A Laravel package for the Firebase PHP Admin SDK

1.3k16.5M42](/packages/kreait-laravel-firebase)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)

PHPackages © 2026

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