From d2c96bb913de05809fc374286510028e8f6b922d Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Wed, 5 Aug 2026 11:55:40 +0200 Subject: [PATCH 1/4] Fix tenants:seed command name via configure() (#1474) Replaces the version_compare hack with a configure() override that sets the command name, which works regardless of whether the installed Laravel version's SeedCommand uses $name or $signature. --- src/Commands/Seed.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Commands/Seed.php b/src/Commands/Seed.php index 5b9db3c4..310b14d6 100644 --- a/src/Commands/Seed.php +++ b/src/Commands/Seed.php @@ -18,21 +18,28 @@ class Seed extends SeedCommand public function __construct(ConnectionResolverInterface $resolver) { - // See https://github.com/archtechx/tenancy/issues/1474 - if (version_compare(app()->version(), '13.24.0', '>=')) { - $this->signature = 'tenants:seed - {class? : The class name of the root seeder} - {--class=Database\\Seeders\\DatabaseSeeder : The class name of the root seeder} - {--database= : The database connection to seed} - {--force : Force the operation to run when in production}'; - parent::__construct($resolver); + parent::__construct($resolver); + + // Our --tenants/--skip-tenants/--with-pending options only get added automatically + // when the parent command isn't signature-based. Since Laravel 13.24, SeedCommand is, + // so we add them ourselves here -- checking first so we don't add them twice on older + // Laravel versions, where they're already there by this point. + if (! $this->getDefinition()->hasOption('tenants')) { $this->specifyParameters(); - } else { - $this->name = 'tenants:seed'; - parent::__construct($resolver); } } + protected function configure(): void + { + parent::configure(); + + // We inherit SeedCommand's name ('db:seed') since we don't redeclare $name/$signature, + // so without this we'd overwrite Laravel's own db:seed command (see #1474). configure() + // always runs after the name is set, regardless of Laravel version, so setting it here + // is safe no matter which of $name/$signature the installed Laravel version uses. + $this->setName('tenants:seed'); + } + public function handle(): int { foreach (config('tenancy.seeder_parameters') as $parameter => $value) { From c74761201fe8ad927cd1dea91dc06057afad5dba Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Wed, 5 Aug 2026 12:11:58 +0200 Subject: [PATCH 2/4] Add regression test for tenants:seed/db:seed command name collision --- tests/CommandsTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index faa897bf..1318cb8e 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -16,7 +16,9 @@ use Stancl\Tenancy\Jobs\DeleteDatabase; use Illuminate\Database\DatabaseManager; use Stancl\Tenancy\Events\TenantCreated; use Stancl\Tenancy\Events\TenantDeleted; +use Stancl\Tenancy\Commands\Seed; use Stancl\Tenancy\Tests\Etc\TestSeeder; +use Illuminate\Database\Console\Seeds\SeedCommand; use Stancl\Tenancy\Events\DeletingTenant; use Stancl\Tenancy\Events\DatabaseMigrated; use Stancl\Tenancy\Tests\Etc\ExampleSeeder; @@ -288,6 +290,16 @@ test('seed command works', function () { }); }); +test('tenants:seed does not overwrite db:seed', function () { + $commands = Artisan::all(); + + expect($commands)->toHaveKey('db:seed') + ->and($commands)->toHaveKey('tenants:seed') + ->and($commands['db:seed'])->toBeInstanceOf(SeedCommand::class) + ->and($commands['db:seed'])->not()->toBeInstanceOf(Seed::class) + ->and($commands['tenants:seed'])->toBeInstanceOf(Seed::class); +}); + test('database connection is switched to default after running commands', function (bool $initializeTenancy) { $tenant = Tenant::create(); From 5a5ab2baf6f8c35102e5c3a3b50d2292c71cf4fd Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 6 Aug 2026 12:01:02 +0200 Subject: [PATCH 3/4] Remove explanatory comments from Seed::__construct and configure() --- src/Commands/Seed.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Commands/Seed.php b/src/Commands/Seed.php index 310b14d6..dd3e46ad 100644 --- a/src/Commands/Seed.php +++ b/src/Commands/Seed.php @@ -20,10 +20,6 @@ class Seed extends SeedCommand { parent::__construct($resolver); - // Our --tenants/--skip-tenants/--with-pending options only get added automatically - // when the parent command isn't signature-based. Since Laravel 13.24, SeedCommand is, - // so we add them ourselves here -- checking first so we don't add them twice on older - // Laravel versions, where they're already there by this point. if (! $this->getDefinition()->hasOption('tenants')) { $this->specifyParameters(); } @@ -33,10 +29,6 @@ class Seed extends SeedCommand { parent::configure(); - // We inherit SeedCommand's name ('db:seed') since we don't redeclare $name/$signature, - // so without this we'd overwrite Laravel's own db:seed command (see #1474). configure() - // always runs after the name is set, regardless of Laravel version, so setting it here - // is safe no matter which of $name/$signature the installed Laravel version uses. $this->setName('tenants:seed'); } From dd34ebd64d89edcba8007d192e6835eec9f0f1be Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 8 Aug 2026 20:21:38 +0200 Subject: [PATCH 4/4] Restore explanatory comments in Seed::__construct and configure() --- src/Commands/Seed.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Commands/Seed.php b/src/Commands/Seed.php index dd3e46ad..310b14d6 100644 --- a/src/Commands/Seed.php +++ b/src/Commands/Seed.php @@ -20,6 +20,10 @@ class Seed extends SeedCommand { parent::__construct($resolver); + // Our --tenants/--skip-tenants/--with-pending options only get added automatically + // when the parent command isn't signature-based. Since Laravel 13.24, SeedCommand is, + // so we add them ourselves here -- checking first so we don't add them twice on older + // Laravel versions, where they're already there by this point. if (! $this->getDefinition()->hasOption('tenants')) { $this->specifyParameters(); } @@ -29,6 +33,10 @@ class Seed extends SeedCommand { parent::configure(); + // We inherit SeedCommand's name ('db:seed') since we don't redeclare $name/$signature, + // so without this we'd overwrite Laravel's own db:seed command (see #1474). configure() + // always runs after the name is set, regardless of Laravel version, so setting it here + // is safe no matter which of $name/$signature the installed Laravel version uses. $this->setName('tenants:seed'); }