gpopoteur/flat
Composer 安装命令:
composer require gpopoteur/flat
包简介
Laravel 5 package for creating multi-tenant apps.
README 文档
README
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:
'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
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
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)
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
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
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
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
developbranch 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
gpopoteur/flat 适用场景与选型建议
gpopoteur/flat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 16, 最近一次更新时间为 2015 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「saas」 「tenant」 「multi-tenant」 「multi tenant」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gpopoteur/flat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gpopoteur/flat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gpopoteur/flat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
A PSR-7 compatible library for making CRUD API endpoints
A pluf module to manage current tenant
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-11