Skip to content

Commit

Permalink
Fix installation for projects without stancl/tenancy
Browse files Browse the repository at this point in the history
  • Loading branch information
pxlrbt committed Feb 16, 2024
1 parent 57fa555 commit d2c3887
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Commands/SeedDatabaseStateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ protected function getFilePath(): string

protected function getStateClasses(): Collection
{
$filesystem = app(Filesystem::class);

if ($filesystem->missing($this->getFilePath())) {
if (! $this->components->confirm("You don't have a `states` folder in your database folder. Do you want to create it?", true)) {
return collect();
}

$filesystem->ensureDirectoryExists($this->getFilePath());
}

return collect(app(Filesystem::class)->files($this->getFilePath()))
->map(fn ($file) => str($file->getPathname())
->replace([base_path(), '.php', 'database/states', '/'], ['', '', 'Database\\States', '\\'])
Expand Down
5 changes: 5 additions & 0 deletions src/DatabaseStateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ public function configurePackage(Package $package): void
->hasCommands([
Commands\MakeCommand::class,
Commands\SeedDatabaseStateCommand::class,
]);

if (class_exists('\Stancl\Tenancy\Concerns\HasTenantOptions')) {
$package->hasCommands([
Commands\SeedTenantsDatabaseStateCommand::class,
]);
}
}

public function packageBooted()
Expand Down

0 comments on commit d2c3887

Please sign in to comment.