Package Data | |
---|---|
Maintainer Username: | ephiot |
Maintainer Contact: | ephiot@gmail.com (Mauricio Queiroz) |
Package Create Date: | 2017-02-22 |
Package Last Update: | 2019-02-15 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-09 15:09:43 |
Package Statistics | |
---|---|
Total Downloads: | 220 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 14 |
Total Watchers: | 4 |
Total Forks: | 1 |
Total Open Issues: | 1 |
A really usefull Multi-Tenancy package for Laravel, it's serious, at least i'm trying to...
composer require protosofia/ben10ant
Add to app/Console/Kernel.php:
...
protected $commands = [
...
\Protosofia\Ben10ant\Commands\TenantCreate::class,
\Protosofia\Ben10ant\Commands\TenantMigrate::class,
\Protosofia\Ben10ant\Commands\TenantMigrateRefresh::class,
\Protosofia\Ben10ant\Commands\TenantMigrateRollback::class,
\Protosofia\Ben10ant\Commands\TenantSeed::class,
...
];
...
Add to app/Http/Kernel.php:
...
protected $middleware = [
...
\Protosofia\Ben10ant\Middlewares\CheckTenantByKey::class,
...
];
...
Add to config/app.php:
...
'providers' => [
...
\Protosofia\Ben10ant\Providers\TenantServiceProvider::class,
...
],
...
Add to config/app.php:
...
'aliases' => [
...
'Tenant' => Protosofia\Ben10ant\Facades\TenantFacade::class,
...
],
...
This package have 3 types of models:
To manage the "tenants" table, you can create a model as below:
...
use Protosofia\Ben10ant\Models\TenantModel;
class Tenant extends TenantModel
{
//
}
To have a tenant user (authenticatable), you can create a model as below:
...
use Protosofia\Ben10ant\Models\TenantAuthenticatableBaseModel;
class User extends TenantAuthenticatableBaseModel
{
use Notifiable;
...
}
To have models to handle tenant data (no authenticatable), you can create a model as below:
...
use Protosofia\Ben10ant\Models\TenantBaseModel;
class YourTenantTable extends TenantBaseModel
{
protected $table = 'your_tenant_table'; //optional
...
}
php artisan vendor:publish
This will publish the config file.
tenant:create {name} {keyname}
This command is a tenant creator wizard, you can configure the database connection and storage.
tenant:migrate {tenant} {--force} {--path} {--pretend} {--step}
This command is an indirect call to 'migrate' command, it set tenant conenction automatically. If the path option is not defined it assumes default path: database/migrations/tenants.
tenant:migrate:refresh {tenant} {--force} {--path} {--seed} {--seeder} {--step}
This command is an indirect call to 'migrate:refresh' command, it set tenant conenction automatically. If the path option is not defined it assumes default path: database/migrations/tenants.
tenant:migrate:rollback {tenant} {--force} {--path} {--seed} {--seeder} {--step}
This command is an indirect call to 'migrate:rollback' command, it set tenant conenction automatically. If the path option is not defined it assumes default path: database/migrations/tenants.
tenant:db:seed {tenant} {--force} {--class}
This command is an indirect call to 'db:seed' command, it set tenant conenction automatically. If the class option is not defined it assumes default class: DatabaseSeeder.
There are 3 middlewares available on the package:
The service is a singleton, accessible from a Facade Tenant. E.g:
...
use Tenant;
$tenant = Tenant::setTenantByUUID($uuid);
if (!$tenant) {
return response()->json(['error' => 'No tenant found.'], 404);
}
...
The service has 4 methods to set tenant: