Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add getTenantName method to Tenant model and update migration c… #1238

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading