Skip to content

Commit d2c3887

Browse files
committed
Fix installation for projects without stancl/tenancy
1 parent 57fa555 commit d2c3887

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Commands/SeedDatabaseStateCommand.php

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ protected function getFilePath(): string
5151

5252
protected function getStateClasses(): Collection
5353
{
54+
$filesystem = app(Filesystem::class);
55+
56+
if ($filesystem->missing($this->getFilePath())) {
57+
if (! $this->components->confirm("You don't have a `states` folder in your database folder. Do you want to create it?", true)) {
58+
return collect();
59+
}
60+
61+
$filesystem->ensureDirectoryExists($this->getFilePath());
62+
}
63+
5464
return collect(app(Filesystem::class)->files($this->getFilePath()))
5565
->map(fn ($file) => str($file->getPathname())
5666
->replace([base_path(), '.php', 'database/states', '/'], ['', '', 'Database\\States', '\\'])

src/DatabaseStateServiceProvider.php

+5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ public function configurePackage(Package $package): void
2424
->hasCommands([
2525
Commands\MakeCommand::class,
2626
Commands\SeedDatabaseStateCommand::class,
27+
]);
28+
29+
if (class_exists('\Stancl\Tenancy\Concerns\HasTenantOptions')) {
30+
$package->hasCommands([
2731
Commands\SeedTenantsDatabaseStateCommand::class,
2832
]);
33+
}
2934
}
3035

3136
public function packageBooted()

0 commit comments

Comments
 (0)