Skip to content

Commit

Permalink
feat: Add getTenantName method to Tenant model and update migration c…
Browse files Browse the repository at this point in the history
…ommand

- 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.
  • Loading branch information
alimousavidev committed Jul 11, 2024
1 parent 8f9c7ef commit 9a98603
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Commands/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function handle()
}

tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
$this->line("Tenant: {$tenant->getTenantName()}");

event(new MigratingDatabase($tenant));

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle()
}

tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
$this->line("Tenant: {$tenant->getTenantName()}");

event(new RollingBackDatabase($tenant));

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Run extends Command
public function handle()
{
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
$this->line("Tenant: {$tenant->getTenantName()}");

$callback = function ($prefix = '') {
return function ($arguments, $argument) use ($prefix) {
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function handle()
}

tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
$this->line("Tenant: {$tenant->getTenantName()}");

event(new SeedingDatabase($tenant));

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/TenantList.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function handle()
->cursor()
->each(function (Tenant $tenant) {
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 {
$this->line("[Tenant] {$tenant->getTenantKeyName()}: {$tenant->getTenantKey()}");
$this->line("[{$tenant->getTenantName()}] {$tenant->getTenantKeyName()}: {$tenant->getTenantKey()}");
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/Contracts/Tenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public function setInternal(string $key, $value);

/** Run a callback in this tenant's environment. */
public function run(callable $callback);

/** Get the human readable name of the tenant. */
public function getTenantName(): string;
}
7 changes: 6 additions & 1 deletion src/Database/Models/Tenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public function newCollection(array $models = []): TenantCollection
{
return new TenantCollection($models);
}


public function getTenantName(): string
{
return $this->getAttribute('name') ?? $this->getTenantKey();
}

protected $dispatchesEvents = [
'saving' => Events\SavingTenant::class,
'saved' => Events\TenantSaved::class,
Expand Down

0 comments on commit 9a98603

Please sign in to comment.