https://github.com/yanhao-li/office-building
🏢 Easy to use SaaS Multitenancy solution for Laravel
https://github.com/yanhao-li/office-building
composer laravel multitenancy multitenant php separate-database
Last synced: 2 months ago
JSON representation
🏢 Easy to use SaaS Multitenancy solution for Laravel
- Host: GitHub
- URL: https://github.com/yanhao-li/office-building
- Owner: yanhao-li
- License: mit
- Created: 2018-03-19T15:57:02.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-20T20:48:30.000Z (almost 8 years ago)
- Last Synced: 2025-12-14T22:54:07.975Z (6 months ago)
- Topics: composer, laravel, multitenancy, multitenant, php, separate-database
- Language: PHP
- Homepage:
- Size: 44.9 KB
- Stars: 27
- Watchers: 5
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Office Building
[](https://travis-ci.org/yanhao-li/office-building)  [](CONTRIBUTING.md#pull-requests)
Office Building is an easy to use Laravel package to help you build the Multi-tenant SaaS with database-per-tenant.
Support Laravel 5.3+
## Installation
Install Office Building via Composer:
```bash
composer require yanhaoli/office-building
```
For laravel >= 5.5 that's all, thanks to [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery).
For laravel <= 5.5, you have to add `Yanhaoli\OfficeBuilding\Providers\OfficeBuildingServiceProvider` to your `config/app.php` providers array:
```php
Yanhaoli\OfficeBuilding\Providers\OfficeBuildingServiceProvider::class,
```
## Usage
1. Config the basis
Firstly you have to publish the config file with the following command:
```php
php artisan vendor:publish --provider="Yanhaoli\OfficeBuilding\Providers\OfficeBuildingServiceProvider"
```
Now checkout `config/officebuilding.php` and modify it by your needs.
2. Open a new Office for your customer
``` php
input('name');
$database_name = OfficeBuilding::addOffice($company_name);
$company = new Company;
$company->name = $company_name;
$company->database_name = $database_name;
$company->save();
return response('created', 201);
}
}
```
3. Handle request for a specific office. Ex, Get all employees of that office
use OfficeBuilding::visit method to switch database connection to a specific office, with a callback method to handle request, the connection will be revert to the previous status after task completed.
```php