mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 19:14:03 +00:00
feat: Add getTenantName method to Tenant model and update migration command
- Implemented getTenantName method in the Tenant model to return the human-readable name of the tenant. - Updated the Tenant interface to include the getTenantName method. - Modified the related command to use getTenantName instead of getTenantKey.
This commit is contained in:
parent
8f9c7efa45
commit
9a98603670
7 changed files with 15 additions and 7 deletions
|
|
@ -49,7 +49,7 @@ class Migrate extends MigrateCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant->getTenantKey()}");
|
$this->line("Tenant: {$tenant->getTenantName()}");
|
||||||
|
|
||||||
event(new MigratingDatabase($tenant));
|
event(new MigratingDatabase($tenant));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class Rollback extends RollbackCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant->getTenantKey()}");
|
$this->line("Tenant: {$tenant->getTenantName()}");
|
||||||
|
|
||||||
event(new RollingBackDatabase($tenant));
|
event(new RollingBackDatabase($tenant));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class Run extends Command
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant->getTenantKey()}");
|
$this->line("Tenant: {$tenant->getTenantName()}");
|
||||||
|
|
||||||
$callback = function ($prefix = '') {
|
$callback = function ($prefix = '') {
|
||||||
return function ($arguments, $argument) use ($prefix) {
|
return function ($arguments, $argument) use ($prefix) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class Seed extends SeedCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant->getTenantKey()}");
|
$this->line("Tenant: {$tenant->getTenantName()}");
|
||||||
|
|
||||||
event(new SeedingDatabase($tenant));
|
event(new SeedingDatabase($tenant));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@ class TenantList extends Command
|
||||||
->cursor()
|
->cursor()
|
||||||
->each(function (Tenant $tenant) {
|
->each(function (Tenant $tenant) {
|
||||||
if ($tenant->domains) {
|
if ($tenant->domains) {
|
||||||
$this->line("[Tenant] {$tenant->getTenantKeyName()}: {$tenant->getTenantKey()} @ " . implode('; ', $tenant->domains->pluck('domain')->toArray() ?? []));
|
$this->line("[{$tenant->getTenantName()}] {$tenant->getTenantKeyName()}: {$tenant->getTenantKey()} @ " . implode('; ', $tenant->domains->pluck('domain')->toArray() ?? []));
|
||||||
} else {
|
} else {
|
||||||
$this->line("[Tenant] {$tenant->getTenantKeyName()}: {$tenant->getTenantKey()}");
|
$this->line("[{$tenant->getTenantName()}] {$tenant->getTenantKeyName()}: {$tenant->getTenantKey()}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,7 @@ interface Tenant
|
||||||
|
|
||||||
/** Run a callback in this tenant's environment. */
|
/** Run a callback in this tenant's environment. */
|
||||||
public function run(callable $callback);
|
public function run(callable $callback);
|
||||||
|
|
||||||
|
/** Get the human readable name of the tenant. */
|
||||||
|
public function getTenantName(): string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,11 @@ class Tenant extends Model implements Contracts\Tenant
|
||||||
return new TenantCollection($models);
|
return new TenantCollection($models);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTenantName(): string
|
||||||
|
{
|
||||||
|
return $this->getAttribute('name') ?? $this->getTenantKey();
|
||||||
|
}
|
||||||
|
|
||||||
protected $dispatchesEvents = [
|
protected $dispatchesEvents = [
|
||||||
'saving' => Events\SavingTenant::class,
|
'saving' => Events\SavingTenant::class,
|
||||||
'saved' => Events\TenantSaved::class,
|
'saved' => Events\TenantSaved::class,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue