diff --git a/src/Commands/TenantsArtisanCommand.php b/src/Commands/TenantsArtisanCommand.php index 2ab1aea..f0c7580 100644 --- a/src/Commands/TenantsArtisanCommand.php +++ b/src/Commands/TenantsArtisanCommand.php @@ -3,6 +3,7 @@ namespace Spatie\Multitenancy\Commands; use Illuminate\Console\Command; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\Artisan; use Spatie\Multitenancy\Models\Tenant; @@ -14,11 +15,17 @@ public function handle() { $tenantQuery = Tenant::query(); - if ($tenantIds = $this->option('tenant')) { - $tenantQuery = $tenantQuery->whereIn('id', $tenantIds); + if (!$artisanCommand = $this->argument('artisanCommand')) { + $artisanCommand = $this->ask('Command to run?'); } - $artisanCommand = $this->argument('artisanCommand'); + if (!$tenantIds = $this->option('tenant')) { + $tenantIds = $this->ask('What tenant ID? Nothing for all tenants.'); + } + + if ($tenantIds) { + $tenantQuery->whereIn('id', Arr::wrap($tenantIds)); + } $tenantQuery ->cursor() diff --git a/tests/Feature/Commands/TenantsArtisanCommandTest.php b/tests/Feature/Commands/TenantsArtisanCommandTest.php index a7d422e..1638ac5 100644 --- a/tests/Feature/Commands/TenantsArtisanCommandTest.php +++ b/tests/Feature/Commands/TenantsArtisanCommandTest.php @@ -35,7 +35,9 @@ public function setUp(): void /** @test */ public function it_can_migrate_all_tenant_databases() { - $this->artisan('tenants:artisan migrate')->assertExitCode(0); + $this->artisan('tenants:artisan migrate') + ->expectsQuestion('What tenant ID? Nothing for all tenants.', '') + ->assertExitCode(0); $this ->assertTenantDatabaseHasTable($this->tenant, 'migrations')