Download the PHP package gpopoteur/flat without Composer
On this page you can find all versions of the php package gpopoteur/flat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gpopoteur/flat
More information about gpopoteur/flat
Files in gpopoteur/flat
Package flat
Short Description Laravel 5 package for creating multi-tenant apps.
License MIT
Homepage https://github.com/gpopoteur/flat
Informations about the package 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 via composer with the command:
composer require gpopoteur/flat
Then register the provider in the config/app.php
file:
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
You can inject the dependency with Laravel IoC container:
Or just let the App::make()
resolve the class.
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.
After you create a new tenant, the new Schema is not automatically migrated, to run the migrations just run:
or, if migrating several tenants at once, pass an array with the tenants names:
Changing Flats (Tenants)
To change the Tenant programatically you can call the moveIn($name)
method of the Flat
API.
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:
and you should be ready to go.
Example:
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 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:
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
Contributions to the library are more than welcome. To contribute code to this repo, follow this simple steps:
- Fork this project.
- Create a new branch. Ex:
feature/this-thing
- Commit & Push the changes to your repo.
- Do a Pull Request from your branch to the
develop
branch of this repo.
Thanks :)
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
MIT