ringierimu / multi-tenant
This package is abandoned and no longer maintained.
No replacement package was suggested.
Laravel Multi-Tenancy package
dev-master
2019-05-03 14:22 UTC
Requires
- php: >=7.1.3
- illuminate/support: ^5.6 || ^5.7 || ^5.8
Requires (Dev)
- orchestra/testbench: ^3.5
- phpunit/phpunit: ^6.0 || ^7.0
This package is not auto-updated.
Last update: 2024-02-18 16:54:25 UTC
README
The term multi-tenant refers to a software architecture in which a single instance of software runs on a server and serves multiple tenants. A tenant is a group of users who share a common access with specific privileges to the software instance. With a multi-tenant architecture, a software application is designed to provide every tenant a dedicated share of the instance - including its data, configuration, user management, tenant individual functionality and non-functional properties.
Installation
$ composer require ringierimu/multi-tenant
Run migrations
$ php artisan migrate
Configuration
- Open
kernel.php
located inside your Http directory and addRingierimu\MultiTenant\Http\Middleware\TenantMiddleware\TenantMiddleware::class
to your global http middleware$middleware
.
/** * The application's global HTTP middleware stack. * * These middleware are run during every request to your application. * * @var array */ protected $middleware = [ ... TenantMiddleware::class ];
- Add
TenantDependableTrait
to your model class to support workflow
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Ringierimu\MultiTenant\Traits\TenantDependableTrait; /** * Class Post * @package App */ class Post extends Model { use TenantDependableTrait; }
- Create seeder for the
domains
table to populate table with data and run your seeder.
eg.
<?php use Illuminate\Support\Facades\DB; DB::table('domains')->insert([ 'title' => 'Ringier', 'host' => 'ringier.test', 'alieses' => 'rg', 'country_id' => 1 ]);
Features
Tenants Resolver
- The
TenantMiddleware::class
resolve the tenants through http request. It uses the request domain to querydomains
table. - To get instance of the resolved Tenant, you can use dependency injection to inject
TenantManager
class or use laravel IOC to return existing instance ofTenantManager
class.
<?php $tenantManager = app(Ringierimu\MultiTenant\TenantManager::class); echo $tenantManager->getDomain();
<?php use Ringierimu\MultiTenant\TenantManager; public function login(TenantManager $tenantManager) { echo $tenantManager->getDomain(); }
Tenants App Config
- To add a custom configuration per per Tenants, add directory
tenants
inside the laravel default config directory with the tenantaliases
key as a subdirectory. eg.config/tenants/rg/app.php
.
NB.aliases
key must be the same as the Tenant aliases key set ondomains
table. - Any config keys found inside tenants directory will override any existing key of laravel default config.